Class DeflaterOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
net.sf.jazzlib.DeflaterOutputStream
- All Implemented Interfaces:
Closeable, Flushable, AutoCloseable
- Direct Known Subclasses:
GZIPOutputStream, ZipOutputStream
This is a special FilterOutputStream deflating the bytes that are written
through it. It uses the Deflater for deflating.
A special thing to be noted is that flush() doesn't flush everything in Sun's
JDK, but it does so in jazzlib. This is because Sun's Deflater doesn't have a
way to flush() everything, without finishing the stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]This buffer is used temporarily to retrieve the bytes from the deflater and write them to the underlying output stream.protected DeflaterThe deflater which is used to deflate the stream.Fields inherited from class FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new DeflaterOutputStream with a default Deflater and default buffer size.DeflaterOutputStream(OutputStream out, Deflater defl) Creates a new DeflaterOutputStream with the given Deflater and default buffer size.DeflaterOutputStream(OutputStream out, Deflater defl, int bufsize) Creates a new DeflaterOutputStream with the given Deflater and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Calls finish () and closes the stream.protected voiddeflate()Deflates everything in the def's input buffers.voidfinish()Finishes the stream by calling finish() on the deflater.voidflush()Flushes the stream by calling flush() on the deflater and then on the underlying stream.voidwrite(byte[] buf, int off, int len) Writes a len bytes from an array to the compressed stream.voidwrite(int bval) Writes a single byte to the compressed output stream.Methods inherited from class FilterOutputStream
writeMethods inherited from class OutputStream
nullOutputStream
-
Field Details
-
buf
protected byte[] bufThis buffer is used temporarily to retrieve the bytes from the deflater and write them to the underlying output stream. -
def
The deflater which is used to deflate the stream.
-
-
Constructor Details
-
DeflaterOutputStream
Creates a new DeflaterOutputStream with a default Deflater and default buffer size.- Parameters:
out- the output stream where deflated output should be written.
-
DeflaterOutputStream
Creates a new DeflaterOutputStream with the given Deflater and default buffer size.- Parameters:
out- the output stream where deflated output should be written.defl- the underlying deflater.
-
DeflaterOutputStream
Creates a new DeflaterOutputStream with the given Deflater and buffer size.- Parameters:
out- the output stream where deflated output should be written.defl- the underlying deflater.bufsize- the buffer size.- Throws:
IllegalArgumentException- if bufsize isn't positive.
-
-
Method Details
-
deflate
Deflates everything in the def's input buffers. This will calldef.deflate()until all bytes from the input buffers are processed.- Throws:
IOException
-
flush
Flushes the stream by calling flush() on the deflater and then on the underlying stream. This ensures that all bytes are flushed. This function doesn't work in Sun's JDK, but only in jazzlib.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-
finish
Finishes the stream by calling finish() on the deflater. This was the only way to ensure that all bytes are flushed in Sun's JDK.- Throws:
IOException
-
close
Calls finish () and closes the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
write
Writes a single byte to the compressed output stream.- Overrides:
writein classFilterOutputStream- Parameters:
bval- the byte value.- Throws:
IOException
-
write
Writes a len bytes from an array to the compressed stream.- Overrides:
writein classFilterOutputStream- Parameters:
buf- the byte array.off- the offset into the byte array where to start.len- the number of bytes to write.- Throws:
IOException
-