public class CompressedRTFInputStream extends InputStream
CompressedRTFInputStream
class provides
decompression of compressed RTF data.Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf |
protected int |
bufend |
protected int |
bufstart |
protected static byte[] |
COMPRESSED_RTF_PREBUF
Prebuffered bytes used in RTF-compressed format.
|
protected int |
compressedSize |
protected int |
crc |
protected int |
crc32 |
protected static int[] |
CRC32_TABLE
The lookup table used in the CRC32 calculation
|
protected byte[] |
dict |
protected static int |
DICT_SIZE |
protected int |
dictstart |
protected int |
flagCount |
protected int |
flags |
protected InputStream |
in |
protected int |
magic |
protected static int |
MAGIC_COMPRESSED |
protected static int |
MAGIC_UNCOMPRESSED |
protected int |
out |
protected int |
uncompressedSize |
Constructor and Description |
---|
CompressedRTFInputStream(InputStream in)
Constructs a new CompressedRTFInputStream which reads the
compressed data from the given underlying stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns an estimate of the number of bytes that can be read (or
skipped over) from this input stream without blocking by the next
invocation of a method for this input stream.
|
static int |
calculateCRC32(byte[] buf,
int off,
int len)
Calculates the CRC32 of the given bytes.
|
void |
close()
Closes this input stream and releases any system resources associated
with the stream.
|
static byte[] |
decompressRTF(byte[] src)
Decompresses compressed-RTF data.
|
protected void |
init()
Initializes this stream by reading the compressed RTF header data.
|
protected boolean |
more()
Reads more data into the dictionary buffer.
|
protected boolean |
moreCompressed()
Reads (and decompresses) more compressed data into the dictionary buffer.
|
protected boolean |
moreUncompressed()
Reads more uncompressed data into the dictionary buffer.
|
int |
read()
Reads the next byte of data from the input stream.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from the input stream into
an array of bytes. |
mark, markSupported, read, reset, skip
protected static final int MAGIC_COMPRESSED
protected static final int MAGIC_UNCOMPRESSED
protected static final int DICT_SIZE
protected static byte[] COMPRESSED_RTF_PREBUF
protected static int[] CRC32_TABLE
protected final InputStream in
protected final byte[] buf
protected final byte[] dict
protected int bufstart
protected int bufend
protected int crc
protected int out
protected int dictstart
protected int flagCount
protected int flags
protected int compressedSize
protected int uncompressedSize
protected int magic
protected int crc32
public CompressedRTFInputStream(InputStream in) throws IOException
in
- the stream containing the compressed dataIOException
- if an error occurspublic static int calculateCRC32(byte[] buf, int off, int len)
buf
- the byte array to calculate CRC32 onoff
- the offset of buf at which the CRC32 calculation will startlen
- the number of bytes on which to calculate the CRC32public static byte[] decompressRTF(byte[] src)
This standalone method decompresses the data using a somewhat different algorithm than this stream's algorithm. It trades memory footprint (twice the size of the entire output is kept in memory) for speed (an order of magnitude faster than the stream version).
It also serves as a concise reference implementation for the decompression algorithm.
src
- the compressed-RTF data bytesIllegalArgumentException
- if src does not contain valid
compressed-RTF bytesprotected void init() throws IOException
IOException
- if an error occursprotected boolean moreCompressed() throws IOException
IOException
- if an error occursprotected boolean moreUncompressed() throws IOException
IOException
- if an error occursprotected boolean more() throws IOException
IOException
- if an error occurspublic int available() throws IOException
available
in class InputStream
0
when
it reaches the end of the input stream.IOException
- if an error occurspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
- if an error occurspublic int read() throws IOException
int
in the range 0
to
255
. If no byte is available because the end of the stream
has been reached, the value -1
is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.read
in class InputStream
-1
if the end of the
stream is reachedIOException
- if an error occurspublic int read(byte[] b, int off, int len) throws IOException
len
bytes of data from the input stream into
an array of bytes. An attempt is made to read as many as
len
bytes, but a smaller number may be read.
The number of bytes actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
If len
is zero, then no bytes are read and
0
is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at end of
file, the value -1
is returned; otherwise, at least one
byte is read and stored into b
.
read
in class InputStream
b
- the buffer into which the data is readoff
- the start offset in array b
at which the data is writtenlen
- the maximum number of bytes to read-1
if there is no more data because the end of
the stream has been reachedIOException
- If the first byte cannot be read for any reason
other than end of file, or if the input stream has been closed,
or if some other I/O error occursNullPointerException
- If b
is null
IndexOutOfBoundsException
- If off
is negative,
len
is negative, or len
is greater than
b.length - off
This software is published under the BSD license. Copyright © 2003-${build.year}, CRIXP AG, Switzerland, All rights reserved. Use is subject to license terms.