Top Fields Constructors Methods
org.tukaani.xz.lz

public abstract Class LZEncoder

extends Object
Class Inheritance
Known Direct Subclasses
org.tukaani.xz.lz.BT4, org.tukaani.xz.lz.HC4
Imports
java.io.OutputStream, .IOException, org.tukaani.xz.ArrayCache

Field Summary

Modifier and TypeField and Description
pack-priv final byte[]
pack-priv final int
private boolean
private final int
keepSizeAfter

Number of bytes that must be available, the current byte included, to make hasEnoughData return true.

private final int
keepSizeBefore

Number of bytes to keep available before the current byte when moving the LZ window.

pack-priv final int
public static final int
public static final int
pack-priv final int
private int
private int
pack-priv int
private int

Constructor Summary

AccessConstructor and Description
pack-priv
LZEncoder(int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax, ArrayCache arrayCache)

Creates a new LZEncoder.

Method Summary

Modifier and TypeMethod and Description
public void
copyUncompressed(OutputStream out, int backward, int len)

public int
fillWindow(byte[] in, int off, int len)

Copies new data into the LZEncoder's buffer.

public int
getAvail()

Get the number of bytes available, including the current byte.

private static int
getBufSize(int dictSize, int extraSizeBefore, int extraSizeAfter, int matchLenMax)

Gets the size of the LZ window buffer that needs to be allocated.

public int
getByte(int backward)

Gets the byte from the given backward offset.

public int
getByte(int forward, int backward)

Gets the byte from the given forward minus backward offset.

public static LZEncoder
getInstance(int
dictionary size
dictSize
,
int
number of bytes to keep available in the history in addition to dictSize
extraSizeBefore
,
int
number of bytes that must be available after current position + matchLenMax
extraSizeAfter
,
int
if a match of at least niceLen bytes is found, be happy with it and don't stop looking for longer matches
niceLen
,
int
don't test for matches longer than matchLenMax bytes
matchLenMax
,
int
match finder ID
mf
,
int
match finder search depth limit
depthLimit
,
ArrayCache arrayCache)

Creates a new LZEncoder.

public abstract Matches
getMatches()

Runs match finder for the next byte and returns the matches found.

public int

Returns:

length of the match; it is in the range [0, lenLimit]
getMatchLen
(int
zero-based distance of the match to test
dist
,
int
don't test for a match longer than this
lenLimit
)

Get the length of a match at the given distance.

public int

Returns:

length of the match; it is in the range [0, lenLimit]
getMatchLen
(int
forward offset
forward
,
int
zero-based distance of the match to test
dist
,
int
don't test for a match longer than this
lenLimit
)

Get the length of a match at the given distance and forward offset.

public static int
getMemoryUsage(int dictSize, int extraSizeBefore, int extraSizeAfter, int matchLenMax, int mf)

Gets approximate memory usage of the LZEncoder base structure and the match finder as kibibytes.

public int
getPos()

Gets the lowest four bits of the absolute offset of the current byte.

public boolean
hasEnoughData(int alreadyReadLen)

Tests if there is enough input available to let the caller encode at least one more byte.

public boolean
isStarted()

Returns true if at least one byte has already been run through the match finder.

pack-priv int

Returns:

the number of bytes available or zero if there is not enough input available
movePos
(int
minimum number of available bytes when flushing; encoding may be continued with new input after flushing
requiredForFlushing
,
int
minimum number of available bytes when finishing; encoding must not be continued after finishing or the match finder state may be corrupt
requiredForFinishing
)

Moves to the next byte, checks if there is enough input available, and returns the amount of input available.

private void
moveWindow()

Moves data from the end of the buffer to the beginning, discarding old data and making space for new input.

pack-priv static void
normalize(int[] positions, int positionsCount, int normalizationOffset)

private void
processPendingBytes()

Process pending bytes remaining from preset dictionary initialization or encoder flush operation.

public void
public void
setFinishing()

Marks that there is no more input remaining.

public void
setFlushing()

Marks that all the input needs to be made available in the encoded output.

public void
setPresetDict(int dictSize, byte[] presetDict)

Sets a preset dictionary.

public abstract void
skip(int len)

Skips the given number of bytes in the match finder.

public boolean

Returns:

true if matches are valid, false if match finder is broken
verifyMatches
(Matches
return value from getMatches
matches
)

Verifies that the matches returned by the match finder are valid.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
pack-priv final byte[] buf
bufSizeback to summary
pack-priv final int bufSize
finishingback to summary
private boolean finishing
keepSizeAfterback to summary
private final int keepSizeAfter

Number of bytes that must be available, the current byte included, to make hasEnoughData return true. Flushing and finishing are naturally exceptions to this since there cannot be any data after the end of the uncompressed input.

keepSizeBeforeback to summary
private final int keepSizeBefore

Number of bytes to keep available before the current byte when moving the LZ window.

matchLenMaxback to summary
pack-priv final int matchLenMax
MF_BT4back to summary
public static final int MF_BT4
MF_HC4back to summary
public static final int MF_HC4
niceLenback to summary
pack-priv final int niceLen
pendingSizeback to summary
private int pendingSize
readLimitback to summary
private int readLimit
readPosback to summary
pack-priv int readPos
writePosback to summary
private int writePos

Constructor Detail

LZEncoderback to summary
pack-priv LZEncoder(int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax, ArrayCache arrayCache)

Creates a new LZEncoder. See getInstance.

Method Detail

copyUncompressedback to summary
public void copyUncompressed(OutputStream out, int backward, int len) throws IOException
fillWindowback to summary
public int fillWindow(byte[] in, int off, int len)

Copies new data into the LZEncoder's buffer.

getAvailback to summary
public int getAvail()

Get the number of bytes available, including the current byte.

Note that the result is undefined if getMatches or skip hasn't been called yet and no preset dictionary is being used.

getBufSizeback to summary
private static int getBufSize(int dictSize, int extraSizeBefore, int extraSizeAfter, int matchLenMax)

Gets the size of the LZ window buffer that needs to be allocated.

getByteback to summary
public int getByte(int backward)

Gets the byte from the given backward offset.

The current byte is at 0, the previous byte at 1 etc. To get a byte at zero-based distance, use getByte(dist + 1).

This function is equivalent to getByte(0, backward).

getByteback to summary
public int getByte(int forward, int backward)

Gets the byte from the given forward minus backward offset. The forward offset is added to the current position. This lets one read bytes ahead of the current byte.

getInstanceback to summary
public static LZEncoder getInstance(int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax, int mf, int depthLimit, ArrayCache arrayCache)

Creates a new LZEncoder.

Parameters
dictSize:int

dictionary size

extraSizeBefore:int

number of bytes to keep available in the history in addition to dictSize

extraSizeAfter:int

number of bytes that must be available after current position + matchLenMax

niceLen:int

if a match of at least niceLen bytes is found, be happy with it and don't stop looking for longer matches

matchLenMax:int

don't test for matches longer than matchLenMax bytes

mf:int

match finder ID

depthLimit:int

match finder search depth limit

getMatchesback to summary
public abstract Matches getMatches()

Runs match finder for the next byte and returns the matches found.

getMatchLenback to summary
public int getMatchLen(int dist, int lenLimit)

Get the length of a match at the given distance.

Parameters
dist:int

zero-based distance of the match to test

lenLimit:int

don't test for a match longer than this

Returns:int

length of the match; it is in the range [0, lenLimit]

getMatchLenback to summary
public int getMatchLen(int forward, int dist, int lenLimit)

Get the length of a match at the given distance and forward offset.

Parameters
forward:int

forward offset

dist:int

zero-based distance of the match to test

lenLimit:int

don't test for a match longer than this

Returns:int

length of the match; it is in the range [0, lenLimit]

getMemoryUsageback to summary
public static int getMemoryUsage(int dictSize, int extraSizeBefore, int extraSizeAfter, int matchLenMax, int mf)

Gets approximate memory usage of the LZEncoder base structure and the match finder as kibibytes.

getPosback to summary
public int getPos()

Gets the lowest four bits of the absolute offset of the current byte. Bits other than the lowest four are undefined.

hasEnoughDataback to summary
public boolean hasEnoughData(int alreadyReadLen)

Tests if there is enough input available to let the caller encode at least one more byte.

isStartedback to summary
public boolean isStarted()

Returns true if at least one byte has already been run through the match finder.

movePosback to summary
pack-priv int movePos(int requiredForFlushing, int requiredForFinishing)

Moves to the next byte, checks if there is enough input available, and returns the amount of input available.

Parameters
requiredForFlushing:int

minimum number of available bytes when flushing; encoding may be continued with new input after flushing

requiredForFinishing:int

minimum number of available bytes when finishing; encoding must not be continued after finishing or the match finder state may be corrupt

Returns:int

the number of bytes available or zero if there is not enough input available

moveWindowback to summary
private void moveWindow()

Moves data from the end of the buffer to the beginning, discarding old data and making space for new input.

normalizeback to summary
pack-priv static void normalize(int[] positions, int positionsCount, int normalizationOffset)
processPendingBytesback to summary
private void processPendingBytes()

Process pending bytes remaining from preset dictionary initialization or encoder flush operation.

putArraysToCacheback to summary
public void putArraysToCache(ArrayCache arrayCache)
setFinishingback to summary
public void setFinishing()

Marks that there is no more input remaining. The read position can be advanced until the end of the data.

setFlushingback to summary
public void setFlushing()

Marks that all the input needs to be made available in the encoded output.

setPresetDictback to summary
public void setPresetDict(int dictSize, byte[] presetDict)

Sets a preset dictionary. If a preset dictionary is wanted, this function must be called immediately after creating the LZEncoder before any data has been encoded.

skipback to summary
public abstract void skip(int len)

Skips the given number of bytes in the match finder.

verifyMatchesback to summary
public boolean verifyMatches(Matches matches)

Verifies that the matches returned by the match finder are valid. This is meant to be used in an assert statement. This is totally useless for actual encoding since match finder's results should naturally always be valid if it isn't broken.

Parameters
matches:Matches

return value from getMatches

Returns:boolean

true if matches are valid, false if match finder is broken