|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
org.tentackle.util.CompressedOutputStream
public class CompressedOutputStream
Stream to write compressed data to the underlying output stream.
Replacement for GZIPOutputStream and ZipOutputStream of java.util.zip capable for communication link streams like tcp-sockets. The standard classes are only file-capable (relying on EOF-detection). In comlinks, however, there are several packets instead of a single file. Hence, the stream must be blocked, i.e. the (varying) blocksize must become part of the protocol to allow the corresponding input stream to detect the end of the packets. Furthermore, we optimize to compress only packets larger than a certain size. All smaller packets will be transferred uncompressed. For the packet size we use the first two bytes in the packet (short), while MSBit signals whether the packet is compressed or not. Because of this, the maximum buffer size is limited to 32K - 1.
| Field Summary | |
|---|---|
static int |
MAX_BUFFER_SIZE
The maximum compression buffer size. |
| Fields inherited from class java.io.FilterOutputStream |
|---|
out |
| Constructor Summary | |
|---|---|
CompressedOutputStream(OutputStream out)
Creates a compressed output stream with maximum allowed buffersize (32K-1) and a default minCompressSize of 64. |
|
CompressedOutputStream(OutputStream out,
int bufSize,
int minCompressSize)
Creates a compressed output stream. |
|
| Method Summary | |
|---|---|
void |
close()
Overridden to print stats only |
void |
flush()
Flushes this output stream and forces any buffered output bytes to be written out to the stream. |
boolean |
isClosed()
|
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified
byte array starting at offset off to
this output stream. |
void |
write(int b)
Writes the specified byte to this output stream. |
| Methods inherited from class java.io.FilterOutputStream |
|---|
write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MAX_BUFFER_SIZE
| Constructor Detail |
|---|
public CompressedOutputStream(OutputStream out,
int bufSize,
int minCompressSize)
out - the underlying output stream (e.g. from a socket)bufSize - the buffer size for compression. Packets larger than bufSize are split.minCompressSize - the minimum compressed packet size. Smaller packets pass the stream uncompressed.public CompressedOutputStream(OutputStream out)
out - the underlying output stream| Method Detail |
|---|
public void write(int b)
throws IOException
byte to this output stream.
write in class FilterOutputStreamb - the byte.
IOException - if an I/O error occurs.
public void write(byte[] b,
int off,
int len)
throws IOException
len bytes from the specified
byte array starting at offset off to
this output stream.
Packets larger than the buffer size will be split and written to the underlying output stream as separate packets.
write in class FilterOutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.
IOException - if an I/O error occurs.FilterOutputStream.write(int)
public void flush()
throws IOException
flush in interface Flushableflush in class FilterOutputStreamIOException - if an I/O error occurs.FilterOutputStream.out
public void close()
throws IOException
close in interface Closeableclose in class FilterOutputStreamIOException - if an I/O error occurs.FilterOutputStream.flush(),
FilterOutputStream.outpublic boolean isClosed()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||