Class ResourceAlignmentExtraField
- java.lang.Object
-
- org.apache.commons.compress.archivers.zip.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 Summary
Fields Modifier and Type Field Description static intBASE_SIZEstatic ZipShortIDExtra field id used for storing alignment and padding.-
Fields inherited from interface org.apache.commons.compress.archivers.zip.ZipExtraField
EXTRAFIELD_HEADER_SIZE
-
-
Constructor Summary
Constructors Constructor Description ResourceAlignmentExtraField()ResourceAlignmentExtraField(int alignment)ResourceAlignmentExtraField(int alignment, boolean allowMethodChange)ResourceAlignmentExtraField(int alignment, boolean allowMethodChange, int padding)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallowMethodChange()Indicates whether method change is allowed when re-compressing the zip file.shortgetAlignment()Gets requested alignment.byte[]getCentralDirectoryData()The actual data to put into central directory - without Header-ID or length specifier.ZipShortgetCentralDirectoryLength()Length of the extra field in the central directory - without Header-ID or length specifier.ZipShortgetHeaderId()The Header-ID.byte[]getLocalFileDataData()The actual data to put into local file data - without Header-ID or length specifier.ZipShortgetLocalFileDataLength()Length of the extra field in the local file data - without Header-ID or length specifier.voidparseFromCentralDirectoryData(byte[] buffer, int offset, int length)Populate data from this array as if it was in central directory data.voidparseFromLocalFileData(byte[] buffer, int offset, int length)Populate data from this array as if it was in local file data.
-
-
-
Field Detail
-
ID
public static final ZipShort ID
Extra field id used for storing alignment and padding.
-
BASE_SIZE
public static final int BASE_SIZE
- See Also:
- Constant Field Values
-
-
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.
-
getHeaderId
public ZipShort getHeaderId()
Description copied from interface:ZipExtraFieldThe Header-ID.- Specified by:
getHeaderIdin interfaceZipExtraField- Returns:
- The HeaderId value
-
getLocalFileDataLength
public ZipShort getLocalFileDataLength()
Description copied from interface:ZipExtraFieldLength of the extra field in the local file data - without Header-ID or length specifier.- Specified by:
getLocalFileDataLengthin interfaceZipExtraField- Returns:
- the length of the field in the local file data
-
getCentralDirectoryLength
public ZipShort getCentralDirectoryLength()
Description copied from interface:ZipExtraFieldLength of the extra field in the central directory - without Header-ID or length specifier.- Specified by:
getCentralDirectoryLengthin interfaceZipExtraField- Returns:
- the length of the field in the central directory
-
getLocalFileDataData
public byte[] getLocalFileDataData()
Description copied from interface:ZipExtraFieldThe actual data to put into local file data - without Header-ID or length specifier.- Specified by:
getLocalFileDataDatain interfaceZipExtraField- Returns:
- the data
-
getCentralDirectoryData
public byte[] getCentralDirectoryData()
Description copied from interface:ZipExtraFieldThe actual data to put into central directory - without Header-ID or length specifier.- Specified by:
getCentralDirectoryDatain interfaceZipExtraField- Returns:
- the data
-
parseFromLocalFileData
public void parseFromLocalFileData(byte[] buffer, int offset, int length) throws java.util.zip.ZipExceptionDescription copied from interface:ZipExtraFieldPopulate data from this array as if it was in local file data.- Specified by:
parseFromLocalFileDatain interfaceZipExtraField- Parameters:
buffer- the buffer to read data fromoffset- offset into buffer to read datalength- 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.ZipExceptionDescription copied from interface:ZipExtraFieldPopulate data from this array as if it was in central directory data.- Specified by:
parseFromCentralDirectoryDatain interfaceZipExtraField- Parameters:
buffer- the buffer to read data fromoffset- offset into buffer to read datalength- the length of data- Throws:
java.util.zip.ZipException- on error
-
-