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:
-
- "https://developer.android.com/studio/command-line/zipalign.html"
ZipArchiveEntry.setAlignment(int)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate short
private static final int
private boolean
static final int
static final ZipShort
Extra field id used for storing alignment and padding.private int
Fields inherited from interface org.apache.commons.compress.archivers.zip.ZipExtraField
EXTRAFIELD_HEADER_SIZE
-
Constructor Summary
ConstructorsConstructorDescriptionResourceAlignmentExtraField
(int alignment) ResourceAlignmentExtraField
(int alignment, boolean allowMethodChange) ResourceAlignmentExtraField
(int alignment, boolean allowMethodChange, int padding) -
Method Summary
Modifier and TypeMethodDescriptionboolean
Indicates whether method change is allowed when re-compressing the zip file.short
Gets 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.void
parseFromCentralDirectoryData
(byte[] buffer, int offset, int length) Populate data from this array as if it was in central directory data.void
parseFromLocalFileData
(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
public static final int BASE_SIZE- See Also:
-
ALLOW_METHOD_MESSAGE_CHANGE_FLAG
private static final int ALLOW_METHOD_MESSAGE_CHANGE_FLAG- See Also:
-
alignment
private short alignment -
allowMethodChange
private boolean allowMethodChange -
padding
private int padding
-
-
Constructor Details
-
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 Details
-
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
Description copied from interface:ZipExtraField
The Header-ID.- Specified by:
getHeaderId
in interfaceZipExtraField
- Returns:
- The HeaderId value
-
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 interfaceZipExtraField
- Returns:
- the length of the field in the local file data
-
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 interfaceZipExtraField
- 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 interfaceZipExtraField
- 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 interfaceZipExtraField
- Returns:
- the data
-
parseFromLocalFileData
Description copied from interface:ZipExtraField
Populate data from this array as if it was in local file data.- Specified by:
parseFromLocalFileData
in interfaceZipExtraField
- Parameters:
buffer
- the buffer to read data fromoffset
- offset into buffer to read datalength
- the length of data- Throws:
ZipException
- on error
-
parseFromCentralDirectoryData
public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException Description copied from interface:ZipExtraField
Populate data from this array as if it was in central directory data.- Specified by:
parseFromCentralDirectoryData
in interfaceZipExtraField
- Parameters:
buffer
- the buffer to read data fromoffset
- offset into buffer to read datalength
- the length of data- Throws:
ZipException
- on error
-