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 class
LZWDecoder.LZWCompatibilityDecoder
(package private) static class
LZWDecoder.LZWSpecDecoder
(package private) static class
LZWDecoder.LZWString
-
Field Summary
Fields Modifier and Type Field Description (package private) int
bitMask
(package private) int
bitsPerCode
(package private) static int
CLEAR_CODE
Clear: Re-initialize tables.(package private) boolean
eofReached
(package private) static int
EOI_CODE
End of Information.private static int
MAX_BITS
private int
maxCode
private int
maxString
private static int
MIN_BITS
(package private) int
nextBits
(package private) int
nextData
private int
oldCode
private LZWDecoder.LZWString[]
table
private static int
TABLE_SIZE
private int
tableLength
-
Constructor Summary
Constructors Modifier Constructor Description protected
LZWDecoder(int tableSize)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private void
addStringToTable(LZWDecoder.LZWString string)
private static int
bitmaskFor(int bits)
static Decoder
create(boolean oldBitReversedStream)
int
decode(java.io.InputStream stream, java.nio.ByteBuffer buffer)
Decodes up tobuffer.length
bytes from the given input stream, into the given buffer.protected abstract int
getNextCode(java.io.InputStream stream)
private void
init()
private boolean
isInTable(int code)
(package private) static boolean
isOldBitReversedStream(java.io.InputStream stream)
protected abstract int
maxCode()
-
-
-
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.IOException
Description copied from interface:Decoder
Decodes up tobuffer.length
bytes from the given input stream, into the given buffer.- Specified by:
decode
in 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
0
if 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)
-
-