public abstract class LZWInputStream extends CompressorInputStream implements InputStreamStatistics
Generic LZW implementation. It is used internally for the Z decompressor and the Unshrinking Zip file compression method, but may be useful for third-party projects in implementing their own LZW variations.
| Modifier and Type | Field and Description |
|---|---|
protected static int |
DEFAULT_CODE_SIZE |
protected BitInputStream |
in |
protected static int |
UNUSED_PREFIX |
| Modifier | Constructor and Description |
|---|---|
protected |
LZWInputStream(InputStream inputStream,
ByteOrder byteOrder) |
| Modifier and Type | Method and Description |
|---|---|
protected abstract int |
addEntry(int previousCode,
byte character)
Add a new entry to the dictionary.
|
protected int |
addEntry(int previousCode,
byte character,
int maxTableSize)
Adds a new entry if the maximum table size hasn't been exceeded
and returns the new index.
|
protected int |
addRepeatOfPreviousCode()
Add entry for repeat of previousCode we haven't added, yet.
|
void |
close() |
protected abstract int |
decompressNextSymbol()
Read the next code and expand it.
|
protected int |
expandCodeToOutputStack(int code,
boolean addedUnfinishedEntry)
Expands the entry with index code to the output stack and may
create a new entry
|
protected int |
getClearCode() |
protected int |
getCodeSize() |
long |
getCompressedCount() |
protected int |
getPrefix(int offset) |
protected int |
getPrefixesLength() |
protected int |
getTableSize() |
protected void |
incrementCodeSize() |
protected void |
initializeTables(int maxCodeSize)
Initializes the arrays based on the maximum code size.
|
protected void |
initializeTables(int maxCodeSize,
int memoryLimitInKb)
Initializes the arrays based on the maximum code size.
|
int |
read() |
int |
read(byte[] b,
int off,
int len) |
protected int |
readNextCode()
Reads the next code from the stream.
|
protected void |
resetCodeSize() |
protected void |
resetPreviousCode() |
protected void |
setClearCode(int codeSize)
Sets the clear code based on the code size.
|
protected void |
setCodeSize(int cs) |
protected void |
setPrefix(int offset,
int value) |
protected void |
setTableSize(int newSize) |
count, count, getBytesRead, getCount, getUncompressedCount, pushedBackBytesavailable, mark, markSupported, read, reset, skipclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetUncompressedCountprotected static final int DEFAULT_CODE_SIZE
protected static final int UNUSED_PREFIX
protected final BitInputStream in
protected LZWInputStream(InputStream inputStream, ByteOrder byteOrder)
protected abstract int addEntry(int previousCode, byte character) throws IOException
previousCode - the previous codecharacter - the next character to appendIOException - on errorprotected int addEntry(int previousCode, byte character, int maxTableSize)
previousCode - the previous codecharacter - the character to appendmaxTableSize - the maximum table sizeprotected int addRepeatOfPreviousCode() throws IOException
IOException - on errorpublic void close() throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class InputStreamIOExceptionprotected abstract int decompressNextSymbol() throws IOException
IOException - on errorprotected int expandCodeToOutputStack(int code, boolean addedUnfinishedEntry) throws IOException
code - the codeaddedUnfinishedEntry - whether unfinished entries have been addedIOException - on errorprotected int getClearCode()
protected int getCodeSize()
public long getCompressedCount()
getCompressedCount in interface InputStreamStatisticsprotected int getPrefix(int offset)
protected int getPrefixesLength()
protected int getTableSize()
protected void incrementCodeSize()
protected void initializeTables(int maxCodeSize)
maxCodeSize - maximum code sizeIllegalArgumentException - if maxCodeSize is not bigger than 0protected void initializeTables(int maxCodeSize, int memoryLimitInKb) throws MemoryLimitException
maxCodeSize - maximum code sizememoryLimitInKb - maximum allowed estimated memory usage in KbMemoryLimitException - if estimated memory usage is greater than memoryLimitInKbIllegalArgumentException - if maxCodeSize is not bigger than 0public int read() throws IOException
read in class InputStreamIOExceptionpublic int read(byte[] b, int off, int len) throws IOException
read in class InputStreamIOExceptionprotected int readNextCode() throws IOException
IOException - on errorprotected void resetCodeSize()
protected void resetPreviousCode()
protected void setClearCode(int codeSize)
codeSize - code sizeprotected void setCodeSize(int cs)
protected void setPrefix(int offset, int value)
protected void setTableSize(int newSize)
Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.