java.lang.Object
io.smallrye.common.io.archive.Archive
A ZIP archive.
-
Method Summary
Modifier and TypeMethodDescriptionintcompareEntryNameTo(long idx, String name) Compare the name of the entry at the given index to the given name.intcompareEntryNameTo(long idx, String name, int offs) Compare the name of the entry at the given index to the given name, starting at the given offset within the entry name.longcompressedSize(long idx) Returns the compressed size in bytes of the entry at the given index.creationTime(long idx) Returns the creation time of the entry at the given index.longReturns the number of entries in the archive.entryName(long idx) Returns the name of the entry corresponding to the given index..booleanentryNameEquals(long idx, String name) Determine whether the name of the entry at the given index is equal to the given name.booleanentryNameStartsWith(long idx, String prefix) Determine whether the name of the entry at the given index starts with the given prefix.longFind an entry with the given name.longFind an entry with the given name.booleanisDirectory(long idx) Determine whether the entry at the given index represents a directory.booleanisStored(long idx) Determine whether the entry at the given index is stored without compression.mapStoredToBuffer(long idx) Map the uncompressed data of aSTOREDentry directly to a byte buffer.modifiedTime(long idx) Returns the last modification time of the entry at the given index.static ArchiveOpen a ZIP archive from a filesystem file.static Archiveopen(byte[] bytes) Open a ZIP archive from a byte array.static Archiveopen(ByteBuffer buffer) Open a ZIP archive from a byte buffer.openEntry(long idx) Open the entry at the given index as an input stream.voidrelease()Attempt to release some or all of the resources associated with this archive.storedArchive(long idx) Open a nested archive stored at the given index.longuncompressedSize(long idx) Returns the uncompressed size in bytes of the entry at the given index.
-
Method Details
-
open
Open a ZIP archive from a byte array.- Parameters:
bytes- the byte array containing the archive data (must not benull)- Returns:
- the opened archive (not
null) - Throws:
IllegalArgumentException- if the byte array does not contain a valid ZIP archive
-
open
Open a ZIP archive from a byte buffer. The archive is read from the buffer's current position to its limit.- Parameters:
buffer- the byte buffer containing the archive data (must not benull)- Returns:
- the opened archive (not
null) - Throws:
IllegalArgumentException- if the buffer does not contain a valid ZIP archive
-
of
Open a ZIP archive from a filesystem file. The file is mapped into memory, so normally this method should only be used for long-lived instances.- Parameters:
path- the path of the archive file to open (must not benull)- Returns:
- the opened archive (not
null) - Throws:
IOException- if the file cannot be openedIllegalArgumentException- if the file does not contain a valid ZIP archive
-
findEntry
Find an entry with the given name.- Parameters:
name- the name of the entry (must not benull)- Returns:
- the index of the entry, or a negative value indicating the point where the name would be found (
-n - 1)
-
findEntry
Find an entry with the given name.- Parameters:
name- the name of the entry (must not benull)from- the first entry to search (inclusive)to- the last entry to search (exclusive)- Returns:
- the index of the entry, or a negative value indicating the point where the name would be found (
-n - 1)
-
entryCount
public long entryCount()Returns the number of entries in the archive.- Returns:
- the number of entries in the archive
-
entryName
Returns the name of the entry corresponding to the given index..- Parameters:
idx- the index of the entry- Returns:
- the name of the entry corresponding to the given index.
-
entryNameEquals
Determine whether the name of the entry at the given index is equal to the given name. The comparison is performed directly against the encoded entry name without allocating a string.- Parameters:
idx- the index of the entryname- the name to compare against (must not benull)- Returns:
trueif the entry name equals the given name, orfalseotherwise
-
entryNameStartsWith
Determine whether the name of the entry at the given index starts with the given prefix. The comparison is performed directly against the encoded entry name without allocating a string.- Parameters:
idx- the index of the entryprefix- the prefix to test against (must not benull)- Returns:
trueif the entry name starts with the given prefix, orfalseotherwise
-
compareEntryNameTo
Compare the name of the entry at the given index to the given name. The comparison is performed directly against the encoded entry name without allocating a string.- Parameters:
idx- the index of the entryname- the name to compare against (must not benull)- Returns:
- a negative value, zero, or a positive value if the entry name is less than, equal to, or greater than the given name, respectively
-
compareEntryNameTo
Compare the name of the entry at the given index to the given name, starting at the given offset within the entry name. The comparison is performed directly against the encoded entry name without allocating a string.- Parameters:
idx- the index of the entryname- the name to compare against (must not benull)offs- the character offset within the entry name at which to begin the comparison- Returns:
- a negative value, zero, or a positive value if the entry name (from the given offset) is less than, equal to, or greater than the given name, respectively
-
storedArchive
Open a nested archive stored at the given index.- Parameters:
idx- the entry index- Returns:
- the archive (not
null) - Throws:
IllegalArgumentException- if the zip entry is notSTOREDor if the entry does not appear to be a zip fileUnsupportedOperationException- if the entry is encrypted
-
mapStoredToBuffer
Map the uncompressed data of aSTOREDentry directly to a byte buffer. Since the data is stored without compression, this provides a zero-copy view of the entry content.- Parameters:
idx- the entry index- Returns:
- the byte buffer containing the entry data (not
null) - Throws:
IllegalArgumentException- if the entry is not stored with theSTOREDmethodUnsupportedOperationException- if the entry is encrypted
-
openEntry
Open the entry at the given index as an input stream. The returned stream will decompress the data if necessary. Both theSTOREDandDEFLATEcompression methods are supported.- Parameters:
idx- the entry index- Returns:
- the input stream for reading the entry data (not
null) - Throws:
UnsupportedOperationException- if the entry uses an unsupported compression method, an unsupported version, or is encrypted
-
isStored
public boolean isStored(long idx) Determine whether the entry at the given index is stored without compression.- Parameters:
idx- the entry index- Returns:
trueif the entry uses theSTOREDcompression method, orfalseotherwise
-
release
public void release()Attempt to release some or all of the resources associated with this archive. After calling this method, accessing the archive (other than to close it) may incur some unspecified performance penalty. -
compressedSize
public long compressedSize(long idx) Returns the compressed size in bytes of the entry at the given index.- Parameters:
idx- the entry index- Returns:
- the compressed size in bytes of the entry at the given index
-
uncompressedSize
public long uncompressedSize(long idx) Returns the uncompressed size in bytes of the entry at the given index.- Parameters:
idx- the entry index- Returns:
- the uncompressed size in bytes of the entry at the given index
-
creationTime
Returns the creation time of the entry at the given index. The time is determined by checking for NTFS and Unix extended attributes in the entry's extra field data. If no extended attributes are present, the modification date and time from the central directory entry are used as a fallback, interpreted in the system default time zone.- Parameters:
idx- the entry index- Returns:
- the creation time of the entry at the given index
-
modifiedTime
Returns the last modification time of the entry at the given index. The time is determined by checking for NTFS and Unix extended attributes in the entry's extra field data. If no extended attributes are present, the modification date and time from the central directory entry are used as a fallback, interpreted in the system default time zone.- Parameters:
idx- the entry index- Returns:
- the last modification time of the entry at the given index
-
isDirectory
public boolean isDirectory(long idx) Determine whether the entry at the given index represents a directory. An entry is considered a directory if its name ends with'/'.- Parameters:
idx- the entry index- Returns:
trueif the entry is a directory, orfalseotherwise
-