Class LZWDecoder
- java.lang.Object
-
- com.twelvemonkeys.imageio.plugins.tiff.LZWDecoder
-
- All Implemented Interfaces:
Decoder
- Direct Known Subclasses:
LZWDecoder.LZWCompatibilityDecoder,LZWDecoder.LZWSpecDecoder
abstract class LZWDecoder extends java.lang.Object implements Decoder
Lempel–Ziv–Welch (LZW) decompression. LZW is a universal loss-less data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. Inspired by libTiff's LZW decompression.- Version:
- $Id: LZWDecoder.java,v 1.0 08.05.12 21:11 haraldk Exp$
- See Also:
- LZW (Wikipedia)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classLZWDecoder.LZWCompatibilityDecoder(package private) static classLZWDecoder.LZWSpecDecoder(package private) static classLZWDecoder.LZWString
-
Field Summary
Fields Modifier and Type Field Description (package private) intbitMask(package private) intbitsPerCode(package private) static intCLEAR_CODEClear: Re-initialize tables.(package private) booleaneofReached(package private) static intEOI_CODEEnd of Information.private static intMAX_BITSprivate intmaxCodeprivate intmaxStringprivate static intMIN_BITS(package private) intnextBits(package private) intnextDataprivate intoldCodeprivate LZWDecoder.LZWString[]tableprivate static intTABLE_SIZEprivate inttableLength
-
Constructor Summary
Constructors Modifier Constructor Description protectedLZWDecoder(int tableSize)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private voidaddStringToTable(LZWDecoder.LZWString string)private static intbitmaskFor(int bits)static Decodercreate(boolean oldBitReversedStream)intdecode(java.io.InputStream stream, java.nio.ByteBuffer buffer)Decodes up tobuffer.lengthbytes from the given input stream, into the given buffer.protected abstract intgetNextCode(java.io.InputStream stream)private voidinit()private booleanisInTable(int code)(package private) static booleanisOldBitReversedStream(java.io.InputStream stream)protected abstract intmaxCode()
-
-
-
Field Detail
-
CLEAR_CODE
static final int CLEAR_CODE
Clear: Re-initialize tables.- See Also:
- Constant Field Values
-
EOI_CODE
static final int EOI_CODE
End of Information.- See Also:
- Constant Field Values
-
MIN_BITS
private static final int MIN_BITS
- See Also:
- Constant Field Values
-
MAX_BITS
private static final int MAX_BITS
- See Also:
- Constant Field Values
-
TABLE_SIZE
private static final int TABLE_SIZE
- See Also:
- Constant Field Values
-
table
private final LZWDecoder.LZWString[] table
-
tableLength
private int tableLength
-
bitsPerCode
int bitsPerCode
-
oldCode
private int oldCode
-
maxCode
private int maxCode
-
bitMask
int bitMask
-
maxString
private int maxString
-
eofReached
boolean eofReached
-
nextData
int nextData
-
nextBits
int nextBits
-
-
Method Detail
-
bitmaskFor
private static int bitmaskFor(int bits)
-
init
private void init()
-
decode
public int decode(java.io.InputStream stream, java.nio.ByteBuffer buffer) throws java.io.IOExceptionDescription copied from interface:DecoderDecodes up tobuffer.lengthbytes from the given input stream, into the given buffer.- Specified by:
decodein interfaceDecoder- Parameters:
stream- the input stream to decode data frombuffer- buffer to store the read data- Returns:
- the total number of bytes read into the buffer, or
0if there is no more data because the end of the stream has been reached. - Throws:
DecodeException- if encoded data is corrupt.java.io.IOException- if an I/O error occurs.java.io.EOFException- if a premature end-of-file is encountered.
-
addStringToTable
private void addStringToTable(LZWDecoder.LZWString string) throws java.io.IOException
- Throws:
java.io.IOException
-
maxCode
protected abstract int maxCode()
-
isInTable
private boolean isInTable(int code)
-
getNextCode
protected abstract int getNextCode(java.io.InputStream stream) throws java.io.IOException- Throws:
java.io.IOException
-
isOldBitReversedStream
static boolean isOldBitReversedStream(java.io.InputStream stream) throws java.io.IOException- Throws:
java.io.IOException
-
create
public static Decoder create(boolean oldBitReversedStream)
-
-