java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
java.util.zip.DeflaterOutputStream
com.arranger.jarl.io.GZipOutputStreamEx
com.arranger.jarl.io.CompressedOutputStream
- public class CompressedOutputStream
- extends GZipOutputStreamEx
Essentially, CompressedOutputStream is much like DeflaterOutputStream with
these differences:
1) CompressedOutputStream "finishes" the compressed output every time
a 'flush' operation is performed. The stream remains open, however. After
a flush, the compression is reset. This allows one to call flush() and
have the stream truly flush all compressed data. flush() may be called
as often as necessary. Note, that since flush() restarts the compression,
it is much more effecient to call flush as few times as possible (in other
words, send as much data as possible before calling flush). In most cases,
the output stream need not be flushed until you need to wait for a response
from your peer on the data you have sent thus far. Of course, the stream
is automatically flushed when closed.
2) The write(int) method has been slightly optimized over the
DeflaterOutputStream version (DeflaterOutputStream would create a new
one byte buffer every time write was called. CompressedOutputStream
reuses an instance buffer. This means, of course, that
CompressedOutputStream in not inherently thread safe)
3) Simple statistics are kept for the stream: number of uncompressed bytes
written (this would be the number of bytes sent to the write() methods)
and the number of actual compressed output bytes.
|
Method Summary |
void |
close()
Writes remaining compressed data to the output stream and closes the
underlying stream. |
void |
finish()
Finishes writing compressed data to the output stream without closing
the underlying stream. |
void |
flush()
Flushes the stream by calling flush() on the deflater and then
on the underlying stream. |
long |
getCompressedTotalOut()
|
protected static int |
getCompressionLevel()
Obtain compression level |
long |
getUncompressedTotalOut()
|
void |
write(byte[] b,
int off,
int len)
Writes array of bytes to the compressed output stream. |
void |
write(int b)
Writes a single byte to the compressed output stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
COMPRESSION_LEVEL_DEFAULT
protected static final int COMPRESSION_LEVEL_DEFAULT
- See Also:
- Constant Field Values
compressionLevel
protected static int compressionLevel
- This is compression level used for DeflatedCompressionStream
Default value is 3 (possible values are 0 to 9
_compOut
protected long _compOut
_totalOut
protected long _totalOut
_b
private byte[] _b
CompressedOutputStream
public CompressedOutputStream(java.io.OutputStream out)
throws java.io.IOException
CompressedOutputStream
public CompressedOutputStream(java.io.OutputStream out,
int compression)
throws java.io.IOException
getCompressionLevel
protected static int getCompressionLevel()
- Obtain compression level
write
public void write(int b)
throws java.io.IOException
- Description copied from class:
java.util.zip.DeflaterOutputStream
- Writes a single byte to the compressed output stream.
write
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
- Description copied from class:
GZipOutputStreamEx
- Writes array of bytes to the compressed output stream. This method
will block until all the bytes are written.
- Overrides:
write in class GZipOutputStreamEx
flush
public void flush()
throws java.io.IOException
- Description copied from class:
java.util.zip.DeflaterOutputStream
- 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.
finish
public void finish()
throws java.io.IOException
- Description copied from class:
GZipOutputStreamEx
- Finishes writing compressed data to the output stream without closing
the underlying stream. Use this method when applying multiple filters
in succession to the same output stream.
- Overrides:
finish in class GZipOutputStreamEx
getCompressedTotalOut
public long getCompressedTotalOut()
getUncompressedTotalOut
public long getUncompressedTotalOut()
close
public void close()
throws java.io.IOException
- Description copied from class:
GZipOutputStreamEx
- Writes remaining compressed data to the output stream and closes the
underlying stream.
- Overrides:
close in class GZipOutputStreamEx