-
- All Implemented Interfaces:
-
java.lang.Cloneable,org.readium.r2.shared.util.zip.compress.archivers.ArchiveEntry,org.readium.r2.shared.util.zip.compress.archivers.EntryStreamOffsets
public class ZipArchiveEntry extends ZipEntry implements ArchiveEntry, EntryStreamOffsets
Extension that adds better handling of extra fields and provides access to the internal and external file attributes.
The extra data is expected to follow the recommendation of APPNOTE.TXT:
- the extra byte array consists of a sequence of extra fields
- each extra fields starts by a two byte header id followed by a two byte sequence holding the length of the remainder of data.
Any extra data that cannot be parsed by the rules above will be consumed as "unparseable" extra data and treated differently by the methods of this class. Versions prior to Apache Commons Compress 1.1 would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumZipArchiveEntry.CommentSourceIndicates how the comment of this entry has been determined.
public enumZipArchiveEntry.ExtraFieldParsingModeHow to try to parse the extra fields.
Configures the behavior for:
- What shall happen if the extra field content doesn'tfollow the recommended pattern of two-byte id followed by atwo-byte length?
- What shall happen if an extra field is generally supportedby Commons Compress but its content cannot be parsedcorrectly? This may for example happen if the archive iscorrupt, it triggers a bug in Commons Compress or the extrafield uses a version not (yet) supported by CommonsCompress.
public enumZipArchiveEntry.NameSourceIndicates how the name of this entry has been determined.
-
Field Summary
Fields Modifier and Type Field Description public final static intPLATFORM_UNIXpublic final static intPLATFORM_FATpublic final static intCRC_UNKNOWNprivate intmethodprivate longsizeprivate intinternalAttributesprivate intversionRequiredprivate intversionMadeByprivate intplatformprivate intrawFlagprivate longexternalAttributesprivate intalignmentprivate Array<ZipExtraField>extraFieldsprivate Stringnameprivate Array<byte>rawNameprivate longdataOffsetprivate booleanisStreamContiguousprivate ZipArchiveEntry.NameSourcenameSourceprivate ZipArchiveEntry.CommentSourcecommentSourceprivate longdiskNumberStartprivate longtime
-
Constructor Summary
Constructors Constructor Description ZipArchiveEntry(File inputFile, String entryName)Creates a new ZIP entry taking some information from the givenfile and using the provided name. ZipArchiveEntry(ZipEntry entry)Creates a new ZIP entry with fields taken from the specified ZIP entry. ZipArchiveEntry(String name)Creates a new ZIP entry with the specified name. ZipArchiveEntry(ZipArchiveEntry entry)Creates a new ZIP entry with fields taken from the specified ZIP entry.
-
Method Summary
Modifier and Type Method Description intgetMethod()Returns the compression method of this entry, or -1 if thecompression method has not been specified. voidsetMethod(int method)Sets the compression method of this entry. longgetSize()Gets the uncompressed size of the entry data. voidsetSize(long size)Sets the uncompressed size of the entry data. intgetInternalAttributes()Retrieves the internal file attributes. voidsetInternalAttributes(int value)Sets the internal file attributes. intgetVersionRequired()The "version required to expand" field. voidsetVersionRequired(int versionRequired)Sets the "version required to expand" field. intgetVersionMadeBy()The "version made by" field. voidsetVersionMadeBy(int versionMadeBy)Sets the "version made by" field. intgetPlatform()Platform specification to put into the "version madeby" part of the central file header. voidsetPlatform(int platform)Set the platform (UNIX or FAT). intgetRawFlag()The content of the flags field. voidsetRawFlag(int rawFlag)Sets the content of the flags field. longgetExternalAttributes()Retrieves the external file attributes. voidsetExternalAttributes(long value)Sets the external file attributes. intgetAlignment()Gets currently configured alignment. voidsetAlignment(int alignment)Sets alignment for this entry. Array<ZipExtraField>getExtraFields()Retrieves all extra fields that have been parsed successfully. Array<ZipExtraField>getExtraFields(boolean includeUnparseable)Retrieves extra fields. StringgetName()Get the name of the entry. voidsetName(String name)Set the name of the entry. Array<byte>getRawName()Returns the raw bytes that made up the name before it has beenconverted using the configured or guessed encoding. longgetDataOffset()Gets the offset of data stream within the archive file, voidsetDataOffset(long dataOffset)Sets the data offset. booleanisStreamContiguous()Indicates whether the stream is contiguous, i.e. ZipArchiveEntry.NameSourcegetNameSource()The source of the name field value. voidsetNameSource(ZipArchiveEntry.NameSource nameSource)Sets the source of the name field value. ZipArchiveEntry.CommentSourcegetCommentSource()The source of the comment field value. voidsetCommentSource(ZipArchiveEntry.CommentSource commentSource)Sets the source of the comment field value. longgetDiskNumberStart()The number of the split segment this entry starts at. voidsetDiskNumberStart(long diskNumberStart)The number of the split segment this entry starts at. longgetTime()Override to work around bug JDK-8130914 voidsetTime(long time)Override to work around bug JDK-8130914 voidaddAsFirstExtraField(ZipExtraField ze)Adds an extra field - replacing an already present extra fieldof the same type. voidaddExtraField(ZipExtraField ze)Adds an extra field - replacing an already present extra fieldof the same type. Objectclone()Overwrite clone. booleanequals(Object obj)Array<byte>getCentralDirectoryExtra()Retrieves the extra data for the central directory. ZipExtraFieldgetExtraField(ZipShort type)Looks up an extra field by its header id. GeneralPurposeBitgetGeneralPurposeBit()The "general purpose bit" field. DategetLastModifiedDate()Wraps getTime with a Date as theentry's last modified date. Array<byte>getLocalFileDataExtra()Retrieves the extra data for the local file data. intgetUnixMode()Unix permission. inthashCode()Get the hash code of the entry.This uses the name as the hash code. booleanisDirectory()Is this entry a directory? booleanisUnixSymlink()Returns true if this entry represents a unix symlink,in which case the entry's content contains the target pathfor the symlink. voidremoveExtraField(ZipShort type)Remove an extra field. voidsetCentralDirectoryExtra(Array<byte> b)Sets the central directory part of extra fields. voidsetExtra(Array<byte> extra)Parses the given bytes as extra field data and consumes anyunparseable data as an UnparseableExtraFieldData instance. voidsetGeneralPurposeBit(GeneralPurposeBit b)The "general purpose bit" field. voidsetUnixMode(int mode)Sets Unix permissions in a way that is understood by Info-Zip'sunzip command. -
Methods inherited from class java.util.zip.ZipEntry
clone, getComment, getCompressedSize, getCrc, getCreationTime, getExtra, getLastAccessTime, getLastModifiedTime, getMethod, getName, getSize, getTime, hashCode, isDirectory, setComment, setCompressedSize, setCrc, setCreationTime, setExtra, setLastAccessTime, setLastModifiedTime, setMethod, setSize, setTime, toString -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ZipArchiveEntry
ZipArchiveEntry(File inputFile, String entryName)
Creates a new ZIP entry taking some information from the givenfile and using the provided name.- Parameters:
inputFile- file to create the entry fromentryName- name of the entry
-
ZipArchiveEntry
ZipArchiveEntry(ZipEntry entry)
Creates a new ZIP entry with fields taken from the specified ZIP entry.- Parameters:
entry- the entry to get fields from
-
ZipArchiveEntry
ZipArchiveEntry(String name)
Creates a new ZIP entry with the specified name.- Parameters:
name- the name of the entry
-
ZipArchiveEntry
ZipArchiveEntry(ZipArchiveEntry entry)
Creates a new ZIP entry with fields taken from the specified ZIP entry.- Parameters:
entry- the entry to get fields from
-
-
Method Detail
-
getMethod
int getMethod()
Returns the compression method of this entry, or -1 if thecompression method has not been specified.
-
setMethod
void setMethod(int method)
Sets the compression method of this entry.
- Parameters:
method- compression method
-
getSize
long getSize()
Gets the uncompressed size of the entry data.
-
setSize
void setSize(long size)
Sets the uncompressed size of the entry data.
- Parameters:
size- the uncompressed size in bytes
-
getInternalAttributes
int getInternalAttributes()
Retrieves the internal file attributes.
-
setInternalAttributes
void setInternalAttributes(int value)
Sets the internal file attributes.
- Parameters:
value- an{@code int}value
-
getVersionRequired
int getVersionRequired()
The "version required to expand" field.
-
setVersionRequired
void setVersionRequired(int versionRequired)
Sets the "version required to expand" field.
- Parameters:
versionRequired- "version required to expand" field
-
getVersionMadeBy
int getVersionMadeBy()
The "version made by" field.
-
setVersionMadeBy
void setVersionMadeBy(int versionMadeBy)
Sets the "version made by" field.
- Parameters:
versionMadeBy- "version made by" field
-
getPlatform
int getPlatform()
Platform specification to put into the "version madeby" part of the central file header.
-
setPlatform
void setPlatform(int platform)
Set the platform (UNIX or FAT).
- Parameters:
platform- an{@code int}value - 0 is FAT, 3 is UNIX
-
getRawFlag
int getRawFlag()
The content of the flags field.
-
setRawFlag
void setRawFlag(int rawFlag)
Sets the content of the flags field.
- Parameters:
rawFlag- content of the flags field
-
getExternalAttributes
long getExternalAttributes()
Retrieves the external file attributes.
-
setExternalAttributes
void setExternalAttributes(long value)
Sets the external file attributes.
- Parameters:
value- an{@code long}value
-
getAlignment
int getAlignment()
Gets currently configured alignment.
-
setAlignment
void setAlignment(int alignment)
Sets alignment for this entry.
- Parameters:
alignment- requested alignment, 0 for default.
-
getExtraFields
Array<ZipExtraField> getExtraFields()
Retrieves all extra fields that have been parsed successfully.
-
getExtraFields
Array<ZipExtraField> getExtraFields(boolean includeUnparseable)
Retrieves extra fields.
- Parameters:
includeUnparseable- whether to also return unparseableextra fields as UnparseableExtraFieldData if such dataexists.
-
getName
String getName()
Get the name of the entry.
This method returns the raw name as it is stored inside of the archive.
-
getRawName
Array<byte> getRawName()
Returns the raw bytes that made up the name before it has beenconverted using the configured or guessed encoding.
This method will return null if this instance has not beenread from an archive.
-
getDataOffset
long getDataOffset()
Gets the offset of data stream within the archive file,
-
setDataOffset
void setDataOffset(long dataOffset)
Sets the data offset.
- Parameters:
dataOffset- new value of data offset.
-
isStreamContiguous
boolean isStreamContiguous()
Indicates whether the stream is contiguous, i.e. not split amongseveral archive parts, interspersed with control blocks, etc.
-
getNameSource
ZipArchiveEntry.NameSource getNameSource()
The source of the name field value.
-
setNameSource
void setNameSource(ZipArchiveEntry.NameSource nameSource)
Sets the source of the name field value.
- Parameters:
nameSource- source of the name field value
-
getCommentSource
ZipArchiveEntry.CommentSource getCommentSource()
The source of the comment field value.
-
setCommentSource
void setCommentSource(ZipArchiveEntry.CommentSource commentSource)
Sets the source of the comment field value.
- Parameters:
commentSource- source of the comment field value
-
getDiskNumberStart
long getDiskNumberStart()
The number of the split segment this entry starts at.
-
setDiskNumberStart
void setDiskNumberStart(long diskNumberStart)
The number of the split segment this entry starts at.
- Parameters:
diskNumberStart- the number of the split segment this entry starts at.
-
getTime
long getTime()
Override to work around bug JDK-8130914
-
setTime
void setTime(long time)
Override to work around bug JDK-8130914
- Parameters:
time- The last modification time of the entry in millisecondssince the epoch
-
addAsFirstExtraField
void addAsFirstExtraField(ZipExtraField ze)
Adds an extra field - replacing an already present extra fieldof the same type.
The new extra field will be the first one.
- Parameters:
ze- an extra field
-
addExtraField
void addExtraField(ZipExtraField ze)
Adds an extra field - replacing an already present extra fieldof the same type.
If no extra field of the same type exists, the field will beadded as last field.
- Parameters:
ze- an extra field
-
getCentralDirectoryExtra
Array<byte> getCentralDirectoryExtra()
Retrieves the extra data for the central directory.
-
getExtraField
ZipExtraField getExtraField(ZipShort type)
Looks up an extra field by its header id.
- Parameters:
type- the header id
-
getGeneralPurposeBit
GeneralPurposeBit getGeneralPurposeBit()
The "general purpose bit" field.
-
getLastModifiedDate
Date getLastModifiedDate()
-
getLocalFileDataExtra
Array<byte> getLocalFileDataExtra()
Retrieves the extra data for the local file data.
-
getUnixMode
int getUnixMode()
Unix permission.
-
hashCode
int hashCode()
Get the hash code of the entry.This uses the name as the hash code.
-
isDirectory
boolean isDirectory()
Is this entry a directory?
-
isUnixSymlink
boolean isUnixSymlink()
Returns true if this entry represents a unix symlink,in which case the entry's content contains the target pathfor the symlink.
-
removeExtraField
void removeExtraField(ZipShort type)
Remove an extra field.
- Parameters:
type- the type of extra field to remove
-
setCentralDirectoryExtra
void setCentralDirectoryExtra(Array<byte> b)
Sets the central directory part of extra fields.
- Parameters:
b- an array of bytes to be parsed into extra fields
-
setExtra
void setExtra(Array<byte> extra)
Parses the given bytes as extra field data and consumes anyunparseable data as an UnparseableExtraFieldData instance.
- Parameters:
extra- an array of bytes to be parsed into extra fields
-
setGeneralPurposeBit
void setGeneralPurposeBit(GeneralPurposeBit b)
The "general purpose bit" field.
- Parameters:
b- the general purpose bit
-
setUnixMode
void setUnixMode(int mode)
Sets Unix permissions in a way that is understood by Info-Zip'sunzip command.
- Parameters:
mode- an{@code int}value
-
-
-
-