Class GzipCompressorOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.apache.commons.compress.compressors.CompressorOutputStream<OutputStream>
org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Compressed output stream using the gzip format. This implementation improves over the standard
GZIPOutputStream
class by allowing the configuration
of the compression level and the header metadata (file name, comment, modification time, operating system and extra flags).- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
Indicates if the stream has been closedprivate final CRC32
The checksum of the uncompressed dataprivate final byte[]
The buffer receiving the compressed data from the deflaterprivate final Deflater
Deflater used to compress the dataprivate static final int
Header flag indicating a comment follows the headerprivate static final int
Header flag indicating a file name follows the headerFields inherited from class java.io.FilterOutputStream
out
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a gzip compressed output stream with the default parameters.GzipCompressorOutputStream
(OutputStream out, GzipParameters parameters) Creates a gzip compressed output stream with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private void
deflate()
void
finish()
Finishes writing compressed data to the underlying stream without closing it.private byte[]
Gets the bytes encoded in the Charset.void
write
(byte[] buffer) void
write
(byte[] buffer, int offset, int length) void
write
(int b) private void
writeHeader
(GzipParameters parameters) private void
Methods inherited from class org.apache.commons.compress.compressors.CompressorOutputStream
out
Methods inherited from class java.io.FilterOutputStream
flush
-
Field Details
-
FNAME
private static final int FNAMEHeader flag indicating a file name follows the header- See Also:
-
FCOMMENT
private static final int FCOMMENTHeader flag indicating a comment follows the header- See Also:
-
deflater
Deflater used to compress the data -
deflateBuffer
private final byte[] deflateBufferThe buffer receiving the compressed data from the deflater -
closed
private boolean closedIndicates if the stream has been closed -
crc
The checksum of the uncompressed data
-
-
Constructor Details
-
GzipCompressorOutputStream
Creates a gzip compressed output stream with the default parameters.- Parameters:
out
- the stream to compress to- Throws:
IOException
- if writing fails
-
GzipCompressorOutputStream
Creates a gzip compressed output stream with the specified parameters.- Parameters:
out
- the stream to compress toparameters
- the parameters to use- Throws:
IOException
- if writing fails- Since:
- 1.7
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterOutputStream
- Throws:
IOException
-
deflate
- Throws:
IOException
-
finish
Finishes writing compressed data to the underlying stream without closing it.- Throws:
IOException
- on error- Since:
- 1.7
-
getBytes
Gets the bytes encoded in the Charset.If the string cannot be encoded directly with , then use URI-style percent encoding.
- Parameters:
string
- The string to encode.- Returns:
- Throws:
IOException
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
- Since:
- 1.1
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
- Since:
- 1.1
-
write
- Overrides:
write
in classFilterOutputStream
- Throws:
IOException
-
writeHeader
- Throws:
IOException
-
writeTrailer
- Throws:
IOException
-