public class ZipFileOutput extends Object implements Closeable
File
or an OutputStream
.Modifier and Type | Class and Description |
---|---|
class |
ZipFileOutput.ZipFileDataOutputStream
Output stream that can be used to write data for a single zip file.
|
Constructor and Description |
---|
ZipFileOutput(File file)
Start writing a Zip-file to a file.
|
ZipFileOutput(OutputStream outputStream)
Start writing a Zip-file to an output-stream.
|
ZipFileOutput(String filePath)
Start writing a Zip-file to a file-path.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addDirectoryFileInfo(String fileName,
ZipCentralDirectoryFileInfo fileInfo)
Add additional information (most optional_ to the Zip central-directory file-header to be associated with the
file-name parameter This information is written to the end of the Zip-file and which holds information about the
files that is not contained in the
ZipFileHeader . |
void |
addDirectoryFileInfo(ZipCentralDirectoryFileInfo fileInfo)
Add additional information (most optional) to the Zip central-directory file-header to be associated with the
most recent file-header.
|
void |
close()
Close the associated output stream.
|
void |
enableFileBuffering(int maxSizeBuffered,
int maxSizeInMemory)
Attaches a buffered output stream to record the file-data _before_ writing out the file-header.
|
long |
finishFileData()
Called at the end of the file data.
|
long |
finishZip()
Finish writing the zip-file.
|
long |
finishZip(ZipCentralDirectoryEndInfo endInfo)
Finish writing the Zip-file with a comment.
|
void |
flush()
Flush the associated output stream.
|
long |
getNumBytesWritten()
Return the current number of bytes written to the output zip-file stream.
|
OutputStream |
openFileDataOutputStream(boolean raw)
Get an output stream suitable for writing the bytes for a single Zip file-entry.
|
long |
writeFileData(File file)
Write the contents of a file to the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
long |
writeFileData(InputStream inputStream)
Read from the input-stream and write its contents to the the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
long |
writeFileData(String filePath)
Write the contents of a file to the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
long |
writeFileDataAll(byte[] buffer)
Write the complete file data as single byte array to the the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
void |
writeFileDataPart(byte[] buffer)
Write file data as single or multiple byte arrays to the the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
void |
writeFileDataPart(byte[] buffer,
int offset,
int length)
Write file data as single or multiple byte arrays to the the Zip-file stream while encoding it based on the
ZipFileHeader.getCompressionMethod() . |
void |
writeFileHeader(ZipFileHeader fileHeader)
Write a file-header which starts the Zip-file.
|
long |
writeRawFileData(File file)
Write the contents of a file to the Zip-file stream without any encoding.
|
long |
writeRawFileData(InputStream inputStream)
Read from the input-stream and write its contents to the the Zip-file stream without any encoding.
|
long |
writeRawFileData(String filePath)
Write the contents of a file to the Zip-file stream without any encoding.
|
void |
writeRawFileDataPart(byte[] buffer)
Write file data as single or multiple byte arrays to the the Zip-file stream without any encoding.
|
void |
writeRawFileDataPart(byte[] buffer,
int offset,
int length)
Write file data as single or multiple byte arrays to the the Zip-file stream without any encoding.
|
public ZipFileOutput(String filePath) throws FileNotFoundException
close()
to close the stream when you are done.FileNotFoundException
public ZipFileOutput(File file) throws FileNotFoundException
close()
to close the stream when you are done.FileNotFoundException
public ZipFileOutput(OutputStream outputStream)
close()
to close the stream when you are
done.public void enableFileBuffering(int maxSizeBuffered, int maxSizeInMemory)
ZipFileHeader
written before the file-data will contain the encoded size and
the crc32 information as opposed to the ZipDataDescriptor
which is written _after_ the file-data.maxSizeBuffered
- Maximum number of bytes that will be stored by the buffer before it gives up and will write out the
header and the a ZipDataDescriptor
after the file-data.maxSizeInMemory
- Maximum number of bytes that will be stored by in memory. If there is any space above this number but
below the maxSizeBuffered then it will be written to a temporary file.public void writeFileHeader(ZipFileHeader fileHeader)
public void addDirectoryFileInfo(ZipCentralDirectoryFileInfo fileInfo)
ZipFileHeader
.public boolean addDirectoryFileInfo(String fileName, ZipCentralDirectoryFileInfo fileInfo)
ZipFileHeader
.public long writeFileData(String filePath) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header.
NOTE: this method calls finishFileData()
for you.IOException
public long writeRawFileData(String filePath) throws IOException
finishFileData()
for you.IOException
public long writeFileData(File file) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header.
NOTE: this method calls finishFileData()
for you.IOException
public long writeRawFileData(File file) throws IOException
finishFileData()
for you.IOException
public long writeFileData(InputStream inputStream) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header.
NOTE: this method calls finishFileData()
for you.IOException
public long writeRawFileData(InputStream inputStream) throws IOException
finishFileData()
for you.IOException
public OutputStream openFileDataOutputStream(boolean raw)
OutputStream.write(byte[], int, int)
basically calls through to
writeFileDataPart(byte[], int, int)
. A call to OutputStream.close()
calls through to
finishFileData()
.raw
- Set to true to have write() call thru to writeRawFileDataPart(byte[], int, int)
or false to
have it call thru tol writeFileDataPart(byte[], int, int)
.public long writeFileDataAll(byte[] buffer) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header. This method calls
finishFileData()
after the write.IOException
public void writeFileDataPart(byte[] buffer) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header. At the end of the
writing, you must call finishFileData()
.IOException
public void writeRawFileDataPart(byte[] buffer) throws IOException
finishFileData()
.IOException
public void writeFileDataPart(byte[] buffer, int offset, int length) throws IOException
ZipFileHeader.getCompressionMethod()
. Must be called after you write the file-header. At the end of the
writing, you must call finishFileData()
.IOException
public void writeRawFileDataPart(byte[] buffer, int offset, int length) throws IOException
finishFileData()
.IOException
public long finishFileData() throws IOException
writeFileDataPart(byte[])
or
writeFileDataPart(byte[], int, int)
methods have been called.
NOTE: This will write a ZipDataDescriptor
at the end of the file unless a CRC32, compressed, or
uncompressed size was specified in the header.IOException
public long finishZip() throws IOException
finishZip(ZipCentralDirectoryEndInfo)
for more information.IOException
public long finishZip(ZipCentralDirectoryEndInfo endInfo) throws IOException
writeFileHeader(ZipFileHeader)
and
addDirectoryFileInfo(ZipCentralDirectoryFileInfo)
methods. After the file-headers the directory-end
information will be written either in Zip32 or Zip64 mode and lastly, if the end-info is in Zip64 mode, the Zip64
locator.IOException
public long getNumBytesWritten()
public void flush() throws IOException
IOException
public void close() throws IOException
finishZip()
has not been called then it will be called at this
point.close
in interface Closeable
close
in interface AutoCloseable
IOException
This documentation content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.