java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
net.i2p.util.ResettableGZIPOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
- Direct Known Subclasses:
ReusableGZIPOutputStream
GZIP implementation per RFC 1952, reusing java's standard CRC32 and Deflater implementations. The main difference is that this implementation allows its state to be reset to initial values, and hence reused, while the standard GZIPOutputStream writes the GZIP header to the stream on instantiation, rather than on first write.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final CRC32Checksum of the bytes written.private booleanTrue once the gzip footer has been written.private booleanHas the header been written out yet?private longHow much data is in the uncompressed stream?private static final booleanTrue to log the stream's internals.private static final byte[]The gzip header written at the start of each stream.Fields inherited from class DeflaterOutputStream
buf, defFields inherited from class FilterOutputStream
outConstructor Summary
ConstructorsConstructorDescriptionStream writing gzip data to the given output stream.Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddestroy()Calls super.close().private voidObviously not threadsafe, but it's a stream, that's standard.voidfinish()voidreset()Reinitialize everything so we can write a brand new gzip output stream again.voidwrite(byte[] buf) voidwrite(byte[] buf, int off, int len) voidwrite(int b) private voidWrites the checksum and size footer at the end of the stream.Methods inherited from class DeflaterOutputStream
deflate, flushMethods inherited from class OutputStream
nullOutputStream
Field Details
_headerWritten
private boolean _headerWrittenHas the header been written out yet?_writtenSize
private long _writtenSizeHow much data is in the uncompressed stream?_crc32
Checksum of the bytes written.DEBUG
HEADER
private static final byte[] HEADERThe gzip header written at the start of each stream.
Constructor Details
ResettableGZIPOutputStream
Stream writing gzip data to the given output stream.- Parameters:
o- the underlying output stream
Method Details
reset
public void reset()Reinitialize everything so we can write a brand new gzip output stream again.ensureHeaderIsWritten
Obviously not threadsafe, but it's a stream, that's standard.- Throws:
IOException- if writing the header to the underlying stream fails
destroy
Calls super.close(). May not be reused after this.- Throws:
IOException- if the wrapped stream cannot be written to or closed
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classDeflaterOutputStream- Throws:
IOException
finish
- Overrides:
finishin classDeflaterOutputStream- Throws:
IOException
write
- Overrides:
writein classDeflaterOutputStream- Throws:
IOException
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
write
- Overrides:
writein classDeflaterOutputStream- Throws:
IOException