net.freeutils.tnef
public class CompressedRTFInputStream extends InputStream
CompressedRTFInputStream
class provides
decompression of compressed RTF data.
Since: 2009-10-12
Field Summary | |
---|---|
protected byte[] | buf |
protected int | bufend |
protected int | bufstart |
protected int | compressedSize |
protected int | crc |
protected int | crc32 |
protected static byte[] | COMPRESSED_RTF_PREBUF
Prebuffered bytes used in RTF-compressed format. |
protected static int[] | CRC32_TABLE
The lookup table used in the CRC32 calculation |
protected byte[] | dict |
protected int | dictstart |
protected static int | DICT_SIZE |
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 Summary | |
---|---|
CompressedRTFInputStream(InputStream in)
Constructs a new CompressedRTFInputStream which reads the
compressed data from the given underlying stream.
|
Method Summary | |
---|---|
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. |
Parameters: in the stream containing the compressed data
Throws: IOException if an error occurs
Returns: an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking or {@code 0} when it reaches the end of the input stream.
Throws: IOException if an error occurs
Parameters: buf the byte array to calculate CRC32 on off the offset of buf at which the CRC32 calculation will start len the number of bytes on which to calculate the CRC32
Returns: the CRC32 value
Throws: IOException if an error occurs
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.
Parameters: src the compressed-RTF data bytes
Returns: an array containing the decompressed bytes
Throws: IllegalArgumentException if src does not contain valid compressed-RTF bytes
Throws: IOException if an error occurs
Returns: true if more data was read, false if there is no more data available
Throws: IOException if an error occurs
Returns: true if more data was read, false if there is no more data available
Throws: IOException if an error occurs
Returns: true if more data was read, false if there is no more data available
Throws: IOException if an error occurs
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.
Returns: the next byte of data, or -1
if the end of the
stream is reached
Throws: IOException if an error occurs
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
.
Parameters: b the buffer into which the data is read off the start offset in array b
at which the data is written len the maximum number of bytes to read
Returns: the total number of bytes read into the buffer, or
-1
if there is no more data because the end of
the stream has been reached
Throws: IOException 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 occurs NullPointerException If b
is null
IndexOutOfBoundsException If off
is negative,
len
is negative, or len
is greater than
b.length - off