public class CompressedRTFInputStream
extends java.io.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 java.io.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(java.io.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. |
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 java.io.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(java.io.InputStream in) throws java.io.IOException
in
- the stream containing the compressed datajava.io.IOException
- 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 bytesjava.lang.IllegalArgumentException
- if src does not contain valid compressed-RTF bytesprotected void init() throws java.io.IOException
java.io.IOException
- if an error occursprotected boolean moreCompressed() throws java.io.IOException
java.io.IOException
- if an error occursprotected boolean moreUncompressed() throws java.io.IOException
java.io.IOException
- if an error occursprotected boolean more() throws java.io.IOException
java.io.IOException
- if an error occurspublic int available() throws java.io.IOException
available
in class java.io.InputStream
0
when
it reaches the end of the input stream.java.io.IOException
- if an error occurspublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
- if an error occurspublic int read() throws java.io.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 java.io.InputStream
-1
if the end of the
stream is reachedjava.io.IOException
- if an error occurspublic int read(byte[] b, int off, int len) throws java.io.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 java.io.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 reachedjava.io.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 occursjava.lang.NullPointerException
- If b
is null
java.lang.IndexOutOfBoundsException
- If off
is negative, len
is
negative, or len
is greater than
b.length - off
Copyright © 2021. All Rights Reserved.