Class ResourceAlignmentExtraField

  • All Implemented Interfaces:
    ZipExtraField

    public class ResourceAlignmentExtraField
    extends java.lang.Object
    implements ZipExtraField
    An extra field who's sole purpose is to align and pad the local file header so that the entry's data starts at a certain position.

    The padding content of the padding is ignored and not retained when reading a padding field.

    This enables Commons Compress to create "aligned" archives similar to Android's zipalign command line tool.

    Since:
    1.14
    See Also:
    "https://developer.android.com/studio/command-line/zipalign.html", ZipArchiveEntry.setAlignment(int)
    • Field Detail

      • ID

        public static final ZipShort ID
        Extra field id used for storing alignment and padding.
    • Constructor Detail

      • ResourceAlignmentExtraField

        public ResourceAlignmentExtraField()
      • ResourceAlignmentExtraField

        public ResourceAlignmentExtraField​(int alignment)
      • ResourceAlignmentExtraField

        public ResourceAlignmentExtraField​(int alignment,
                                           boolean allowMethodChange)
      • ResourceAlignmentExtraField

        public ResourceAlignmentExtraField​(int alignment,
                                           boolean allowMethodChange,
                                           int padding)
    • Method Detail

      • getAlignment

        public short getAlignment()
        Gets requested alignment.
        Returns:
        requested alignment.
      • allowMethodChange

        public boolean allowMethodChange()
        Indicates whether method change is allowed when re-compressing the zip file.
        Returns:
        true if method change is allowed, false otherwise.
      • getLocalFileDataLength

        public ZipShort getLocalFileDataLength()
        Description copied from interface: ZipExtraField
        Length of the extra field in the local file data - without Header-ID or length specifier.
        Specified by:
        getLocalFileDataLength in interface ZipExtraField
        Returns:
        the length of the field in the local file data
      • getCentralDirectoryLength

        public ZipShort getCentralDirectoryLength()
        Description copied from interface: ZipExtraField
        Length of the extra field in the central directory - without Header-ID or length specifier.
        Specified by:
        getCentralDirectoryLength in interface ZipExtraField
        Returns:
        the length of the field in the central directory
      • getLocalFileDataData

        public byte[] getLocalFileDataData()
        Description copied from interface: ZipExtraField
        The actual data to put into local file data - without Header-ID or length specifier.
        Specified by:
        getLocalFileDataData in interface ZipExtraField
        Returns:
        the data
      • getCentralDirectoryData

        public byte[] getCentralDirectoryData()
        Description copied from interface: ZipExtraField
        The actual data to put into central directory - without Header-ID or length specifier.
        Specified by:
        getCentralDirectoryData in interface ZipExtraField
        Returns:
        the data
      • parseFromLocalFileData

        public void parseFromLocalFileData​(byte[] buffer,
                                           int offset,
                                           int length)
                                    throws java.util.zip.ZipException
        Description copied from interface: ZipExtraField
        Populate data from this array as if it was in local file data.
        Specified by:
        parseFromLocalFileData in interface ZipExtraField
        Parameters:
        buffer - the buffer to read data from
        offset - offset into buffer to read data
        length - the length of data
        Throws:
        java.util.zip.ZipException - on error
      • parseFromCentralDirectoryData

        public void parseFromCentralDirectoryData​(byte[] buffer,
                                                  int offset,
                                                  int length)
                                           throws java.util.zip.ZipException
        Description copied from interface: ZipExtraField
        Populate data from this array as if it was in central directory data.
        Specified by:
        parseFromCentralDirectoryData in interface ZipExtraField
        Parameters:
        buffer - the buffer to read data from
        offset - offset into buffer to read data
        length - the length of data
        Throws:
        java.util.zip.ZipException - on error