|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
org.bolet.jgz.ZlibInputStream
public class ZlibInputStream
This class implements a decoder stream for a compressed data
stream in zlib
format (RFC 1950).
Such a stream is self-terminated; read()
requests
will return -1 if the logical data end has been reached, regardless
of the status of the underlying stream, which may contain more
data. Zlib
streams have an internal 32-bit checksum,
which this implementation verifies when the stream logical end is
reached (a read attempt beyond the end is enough to trigger this
verification; calling close()
also works).
Zlib
streams may use a dictionary, which is a bunch
of uncompressed data that the compressor may use for backward
references, as if it has been compressed and transmitted beforehand.
The checksum is
The stream may be initialized with the partial
flag
set; in that mode, read()
requests mark a stop at the
end of each deflate block. More precisely, read(byte[])
and read(byte[],int,int)
normally process input data
until the logical stream end or the output buffer size, whichever
comes first; in partial
mode, these functions will
return bytes from only one deflate block at most. This allows the
calling application to implement stateful interruptions, as is
required for some streaming protocols (e.g. SSH). A consequence is
that read(byte[])
and read(byte[],int,int)
may return 0, if the next block happens to be empty
(warning: this is in violation of the
InputStream
API).
Field Summary | |
---|---|
static int |
DEFLATE
Compression method: the "deflate" algorithm (RFC 1951). |
Constructor Summary | |
---|---|
ZlibInputStream(java.io.InputStream sub)
Create the stream. |
|
ZlibInputStream(java.io.InputStream sub,
boolean partial)
Create the stream. |
Method Summary | |
---|---|
void |
close()
This close() method checks that the logical
end-of-stream has been reached; the checksum is verified if
this has not already been done. |
int |
getCompressionInfo()
Get the compression information. |
int |
getCompressionLevel()
Get the compression level. |
int |
getCompressionMethod()
Get the compression method (normally DEFLATE ). |
int |
getDictionaryId()
Get the dictionary identifier; if none was provided, then 0 is returned (but a valid dictionary could also use the identifier value of 0; use hasDictionary() to
know if a dictionary ID was supplied in the stream). |
boolean |
hasDictionary()
Tell whether a dictionary was used by the compressor. |
void |
processDictionary(byte[] dict)
Process a dictionary: the buffer contents are used as dictionary. |
void |
processDictionary(byte[] dict,
int off,
int len)
Process a dictionary: the buffer contents are used as dictionary. |
void |
processDictionary(java.io.InputStream dict)
Process a dictionary: the stream contents are used as dictionary. |
int |
read()
|
int |
read(byte[] buf)
|
int |
read(byte[] buf,
int off,
int len)
|
void |
setRawStream(java.io.InputStream sub)
Change the raw stream used to get compressed data bytes. |
Methods inherited from class java.io.InputStream |
---|
available, mark, markSupported, reset, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFLATE
Constructor Detail |
---|
public ZlibInputStream(java.io.InputStream sub) throws java.io.IOException
zlib
header is
immediately read and decoded. This constructor is equivalent
to the two-parameter constructor with the
partial
parameter set to false
.
sub
- the underlying input stream
java.io.IOException
- on I/O or format errorpublic ZlibInputStream(java.io.InputStream sub, boolean partial) throws java.io.IOException
zlib
header is
immediately read and decoded. Note: if partial mode is
enabled, then the read()
methods may return 0
(although some input data will be consumed in the process).
sub
- the underlying input streampartial
- true
to use partial mode
java.io.IOException
- on I/O or format errorMethod Detail |
---|
public int getCompressionMethod()
DEFLATE
).
public int getCompressionInfo()
n
, then the backward
sequence references may reach up to 2^(n+8)
previously uncompressed bytes; the maximum standard value for
n
is then 7 (which implies a 32 kB window).
public int getCompressionLevel()
public boolean hasDictionary()
true
, then the same dictionary
must be input; the dictionary identifier can be retrieved
with the getDictionaryId()
method.
true
for a dictionarypublic int getDictionaryId()
hasDictionary()
to
know if a dictionary ID was supplied in the stream).
public void processDictionary(java.io.InputStream dict) throws java.io.IOException
dict
- the dictionary stream
java.io.IOException
- on I/O error with dict
public void processDictionary(byte[] dict)
dict
- the dictionarypublic void processDictionary(byte[] dict, int off, int len)
dict
- the dictionaryoff
- the dictionary offsetlen
- the dictionary lengthpublic void setRawStream(java.io.InputStream sub)
sub
- the new input streampublic void close() throws java.io.IOException
close()
method checks that the logical
end-of-stream has been reached; the checksum is verified if
this has not already been done. Moreover, the underlying
stream is also closed.
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.io.IOException
InputStream
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
InputStream
public int read(byte[] buf) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
InputStream
public int read(byte[] buf, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
InputStream
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |