Package kala.compress.compressors.gzip
Class GzipCompressorOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- kala.compress.compressors.CompressorOutputStream<java.io.OutputStream>
-
- kala.compress.compressors.gzip.GzipCompressorOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class GzipCompressorOutputStream extends CompressorOutputStream<java.io.OutputStream>
Compressed output stream using the gzip format. This implementation improves over the standardGZIPOutputStreamclass by allowing the configuration of the compression level and the header metadata (file name, comment, modification time, operating system and extra flags).- See Also:
- RFC 1952 GZIP File Format Specification
-
-
Field Summary
Fields Modifier and Type Field Description private booleanclosedIndicates if the stream has been closedprivate java.util.zip.CRC32crcThe checksum of the uncompressed dataprivate byte[]deflateBufferThe buffer receiving the compressed data from the deflaterprivate java.util.zip.DeflaterdeflaterDeflater used to compress the dataprivate static intFCOMMENTHeader flag indicating a comment follows the headerprivate static intFEXTRAHeader flag indicating an EXTRA subfields collection follows the headerprivate static intFNAMEHeader flag indicating a file name follows the header
-
Constructor Summary
Constructors Constructor Description GzipCompressorOutputStream(java.io.OutputStream out)Creates a gzip compressed output stream with the default parameters.GzipCompressorOutputStream(java.io.OutputStream out, GzipParameters parameters)Creates a gzip compressed output stream with the specified parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()private voiddeflate()voidfinish()Finishes writing compressed data to the underlying stream without closing it.voidwrite(byte[] buffer)voidwrite(byte[] buffer, int offset, int length)voidwrite(int b)private voidwrite(java.lang.String value, java.nio.charset.Charset charset)Writes a NUL-terminated String encoded with thecharset.private voidwriteHeader(GzipParameters parameters)private voidwriteTrailer()-
Methods inherited from class kala.compress.compressors.CompressorOutputStream
out
-
-
-
-
Field Detail
-
FEXTRA
private static final int FEXTRA
Header flag indicating an EXTRA subfields collection follows the header- See Also:
- Constant Field Values
-
FNAME
private static final int FNAME
Header flag indicating a file name follows the header- See Also:
- Constant Field Values
-
FCOMMENT
private static final int FCOMMENT
Header flag indicating a comment follows the header- See Also:
- Constant Field Values
-
deflater
private final java.util.zip.Deflater deflater
Deflater used to compress the data
-
deflateBuffer
private final byte[] deflateBuffer
The buffer receiving the compressed data from the deflater
-
closed
private boolean closed
Indicates if the stream has been closed
-
crc
private final java.util.zip.CRC32 crc
The checksum of the uncompressed data
-
-
Constructor Detail
-
GzipCompressorOutputStream
public GzipCompressorOutputStream(java.io.OutputStream out) throws java.io.IOExceptionCreates a gzip compressed output stream with the default parameters.- Parameters:
out- the stream to compress to- Throws:
java.io.IOException- if writing fails
-
GzipCompressorOutputStream
public GzipCompressorOutputStream(java.io.OutputStream out, GzipParameters parameters) throws java.io.IOExceptionCreates a gzip compressed output stream with the specified parameters.- Parameters:
out- the stream to compress toparameters- the parameters to use- Throws:
java.io.IOException- if writing fails- Since:
- 1.7
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
deflate
private void deflate() throws java.io.IOException- Throws:
java.io.IOException
-
finish
public void finish() throws java.io.IOExceptionFinishes writing compressed data to the underlying stream without closing it.- Throws:
java.io.IOException- on error- Since:
- 1.7
-
write
public void write(byte[] buffer) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException- Since:
- 1.1
-
write
public void write(byte[] buffer, int offset, int length) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException- Since:
- 1.1
-
write
public void write(int b) throws java.io.IOException- Overrides:
writein classjava.io.FilterOutputStream- Throws:
java.io.IOException
-
write
private void write(java.lang.String value, java.nio.charset.Charset charset) throws java.io.IOExceptionWrites a NUL-terminated String encoded with thecharset.- Parameters:
value- The String to write.charset- Specifies the Charset to use.- Throws:
java.io.IOException- if an I/O error occurs.
-
writeHeader
private void writeHeader(GzipParameters parameters) throws java.io.IOException
- Throws:
java.io.IOException
-
writeTrailer
private void writeTrailer() throws java.io.IOException- Throws:
java.io.IOException
-
-