public class ZipFileInput extends Object implements Closeable
File
or an InputStream
.Modifier and Type | Class and Description |
---|---|
class |
ZipFileInput.ZipFileDataInputStream
Input stream that can be used to read data for a single Zip file-entry.
|
Constructor and Description |
---|
ZipFileInput(File file)
Read a Zip-file from a file.
|
ZipFileInput(InputStream inputStream)
Read a Zip-file from an input-stream.
|
ZipFileInput(String path)
Start reading a Zip-file from the file-path.
|
Modifier and Type | Method and Description |
---|---|
boolean |
assignDirectoryFileEntryPermissions(ZipCentralDirectoryFileEntry entry)
Assigns the file permissions from the current dir-entry to the File that was previously read by
readFileDataToFile(File) . |
void |
close()
Close the underlying input-stream.
|
Iterator<ZipCentralDirectoryFileEntry> |
directoryFileEntryIterator()
Return an iterator that can be used to step across the central-directory file entries.
|
Iterator<ZipFileHeader> |
fileHeaderIterator()
Return an iterator that can be used to step across the file-headers.
|
ZipDataDescriptor |
getCurrentDataDescriptor()
After all of the Zip data has been read from the stream there may be an optional data-descriptor depending on
whether or not the file-header has the
GeneralPurposeFlag.DATA_DESCRIPTOR flag set. |
ZipFileDataInfo |
getCurrentFileCountingInfo()
Return some counting and CRC information from the current file that was read.
|
String |
getCurrentFileName()
Return the file-name from the most recent header read or null if none.
|
long |
getNumBytesRead()
Return the number of bytes that have been read so far in the stream.
|
boolean |
isFileDataEofReached()
Returns true if the current file's data EOF has been reached.
|
InputStream |
openFileDataInputStream(boolean raw)
Get an input stream suitable for reading the bytes of a single Zip file-entry.
|
ZipCentralDirectoryEnd |
readDirectoryEnd()
Read the central-directory end which is after all of the central-directory file-headers at the very end of the
Zip file.
|
boolean |
readDirectoryFileEntriesAndAssignPermissions()
Reads in all of the file-entries from the Zip central-directory and assigns the permissions on the files that
were previously read by
readFileDataToFile(File) and that matches the file-header written with the File. |
ZipCentralDirectoryFileEntry |
readDirectoryFileEntry()
After all of the files have been read, you can read and examine the central-directory entries.
|
long |
readFileData(OutputStream outputStream)
Read file data from the Zip stream, decode it, and write it to the output-steam argument.
|
int |
readFileDataPart(byte[] buffer)
Read file data from the Zip stream and decode it into the buffer argument.
|
int |
readFileDataPart(byte[] buffer,
int offset,
int length)
Read file data from the Zip stream and decode it into the buffer argument.
|
long |
readFileDataToFile(File outputFile)
Read file data from the Zip stream, decode it, and write it to the file argument.
|
long |
readFileDataToFile(String outputPath)
Read file data from the Zip stream, decode it, and write it to the file path argument.
|
ZipFileHeader |
readFileHeader()
Read the next file header from the zip file.
|
long |
readRawFileData(OutputStream outputStream)
Read raw file data from the Zip stream, no decoding, and write it to the output-steam argument.
|
int |
readRawFileDataPart(byte[] buffer)
Read raw file data from the Zip stream, without decoding, into the buffer argument.
|
int |
readRawFileDataPart(byte[] buffer,
int offset,
int length)
Read raw file data from the Zip stream, without decoding, into the buffer argument.
|
long |
readRawFileDataToFile(File outputFile)
Read raw file data from the Zip stream, decode it, and write it to the file argument.
|
long |
readRawFileDataToFile(String outputPath)
Read raw file data from the Zip stream, decode it, and write it to the file path argument.
|
void |
readToEndOfZip()
In some circumstances we need to read to the EOF marker in case we are in an inner Zip file.
|
Zip64CentralDirectoryEnd |
readZip64DirectoryEnd()
Read the central-directory end which is after all of the central-directory file-headers at the very end of the
Zip file.
|
Zip64CentralDirectoryEndLocator |
readZip64DirectoryEndLocator()
Read the central-directory end locator which is after the zip64 end structure.
|
void |
setReadTillEof(boolean readTillEof)
By default the reader will read to the end of the zip-file when
close() is called if we are reading from
an input-stream to handle the possibility of being a Zip within a Zip. |
long |
skipFileData()
Skip over the file data in the zip.
|
public ZipFileInput(String path) throws FileNotFoundException
close()
to close the stream when you are
done.FileNotFoundException
public ZipFileInput(File file) throws FileNotFoundException
close()
to close the stream when you are done.FileNotFoundException
public ZipFileInput(InputStream inputStream)
close()
to close the stream when you are done.public ZipFileHeader readFileHeader() throws IOException
IOException
public Iterator<ZipFileHeader> fileHeaderIterator()
Iterator.hasNext()
and null for Iterator.next()
once the end has been reached.public long skipFileData() throws IOException
IOException
public long readFileDataToFile(String outputPath) throws IOException
outputPath
- Where to write the data read from the zip stream.IOException
public long readFileDataToFile(File outputFile) throws IOException
assignDirectoryFileEntryPermissions(ZipCentralDirectoryFileEntry)
or
readDirectoryFileEntriesAndAssignPermissions()
.outputFile
- Where to write the data read from the zip stream.IOException
public long readFileData(OutputStream outputStream) throws IOException
IOException
public long readRawFileData(OutputStream outputStream) throws IOException
IOException
public InputStream openFileDataInputStream(boolean raw)
InputStream.read(byte[], int, int)
basically calls through to
readFileDataPart(byte[], int, int)
.
NOTE: you _must_ read from the input-stream until it returns EOF (-1).raw
- Set to true to have read() call thru to readRawFileDataPart(byte[], int, int)
or false to
have it call thru to readFileDataPart(byte[], int, int)
.public int readFileDataPart(byte[] buffer) throws IOException
readFileDataPart(byte[], int, int)
for more details.IOException
public long readRawFileDataToFile(String outputPath) throws IOException
outputPath
- Where to write the data read from the zip stream.IOException
public long readRawFileDataToFile(File outputFile) throws IOException
assignDirectoryFileEntryPermissions(ZipCentralDirectoryFileEntry)
or
readDirectoryFileEntriesAndAssignPermissions()
.outputFile
- Where to write the data read from the zip stream.IOException
public int readRawFileDataPart(byte[] buffer) throws IOException
readRawFileDataPart(byte[], int, int)
for more details.IOException
public int readFileDataPart(byte[] buffer, int offset, int length) throws IOException
IOException
public int readRawFileDataPart(byte[] buffer, int offset, int length) throws IOException
IOException
public ZipCentralDirectoryFileEntry readDirectoryFileEntry() throws IOException
IOException
public Iterator<ZipCentralDirectoryFileEntry> directoryFileEntryIterator()
Iterator.hasNext()
and null for Iterator.next()
once the end has been reached.public boolean assignDirectoryFileEntryPermissions(ZipCentralDirectoryFileEntry entry)
readFileDataToFile(File)
. A previous call to readDirectoryFileEntry()
must have been made with
a file-name that matches the file-header written with the File previously. This assigns the permissions based on
a call to ExternalFileAttributesUtils.assignToFile(File, int)
.public boolean readDirectoryFileEntriesAndAssignPermissions() throws IOException
readFileDataToFile(File)
and that matches the file-header written with the File.IOException
public Zip64CentralDirectoryEnd readZip64DirectoryEnd() throws IOException
IOException
public Zip64CentralDirectoryEndLocator readZip64DirectoryEndLocator() throws IOException
IOException
public ZipCentralDirectoryEnd readDirectoryEnd() throws IOException
IOException
public void readToEndOfZip() throws IOException
close()
if
setReadTillEof(boolean)
is set to true which is on by default if the ZipFileInput(InputStream)
constructor is used.IOException
public void close() throws IOException
setReadTillEof(boolean)
.close
in interface Closeable
close
in interface AutoCloseable
IOException
public String getCurrentFileName()
public ZipFileDataInfo getCurrentFileCountingInfo()
public long getNumBytesRead()
public boolean isFileDataEofReached()
public ZipDataDescriptor getCurrentDataDescriptor()
GeneralPurposeFlag.DATA_DESCRIPTOR
flag set. If there is no
descriptor then null is returned here. Once the next header is read this will return null until the end of the
Zip data again has been reached by the next file entry.public void setReadTillEof(boolean readTillEof)
close()
is called if we are reading from
an input-stream to handle the possibility of being a Zip within a Zip. If we don't do this the encoding of the
outer Zip file may not be fully read to the end which would cause processing issues.This documentation content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.