Class ResourceAlignmentExtraField
java.lang.Object
org.apache.commons.compress.archivers.zip.ResourceAlignmentExtraField
- All Implemented Interfaces:
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBase field size.static final ZipShortExtra field id used for storing alignment and padding.Fields inherited from interface org.apache.commons.compress.archivers.zip.ZipExtraField
EXTRAFIELD_HEADER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance.ResourceAlignmentExtraField(int alignment) Constructs a new instance.ResourceAlignmentExtraField(int alignment, boolean allowMethodChange) Constructs a new instance.ResourceAlignmentExtraField(int alignment, boolean allowMethodChange, int padding) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether a method change is allowed when re-compressing the ZIP file.shortGets requested alignment.byte[]The actual data to put into central directory - without Header-ID or length specifier.Length of the extra field in the central directory - without Header-ID or length specifier.The Header-ID.byte[]The actual data to put into local file data - without Header-ID or length specifier.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 Details
-
ID
Extra field id used for storing alignment and padding. -
BASE_SIZE
Base field size.- See Also:
-
-
Constructor Details
-
ResourceAlignmentExtraField
public ResourceAlignmentExtraField()Constructs a new instance. -
ResourceAlignmentExtraField
Constructs a new instance.- Parameters:
alignment- A positive alignment less thanShort.MAX_VALUE.
-
ResourceAlignmentExtraField
Constructs a new instance.- Parameters:
alignment- A positive alignment less thanShort.MAX_VALUE.allowMethodChange- whether a method change is allowed when re-compressing the ZIP file.
-
ResourceAlignmentExtraField
Constructs a new instance.- Parameters:
alignment- A positive alignment less thanShort.MAX_VALUE.allowMethodChange- whether a method change is allowed when re-compressing the ZIP file.padding- padding.
-
-
Method Details
-
allowMethodChange
Indicates whether a method change is allowed when re-compressing the ZIP file.- Returns:
- true if a method change is allowed, false otherwise.
-
getAlignment
Gets requested alignment.- Returns:
- requested alignment.
-
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
-
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
-
getHeaderId
Description copied from interface:ZipExtraFieldThe Header-ID.- Specified by:
getHeaderIdin interfaceZipExtraField- Returns:
- The HeaderId value
-
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
-
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
-
parseFromCentralDirectoryData
public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException Description 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:
ZipException- on error
-
parseFromLocalFileData
Description 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:
ZipException- on error
-