Maven module :un.storage : archive-xz :
Class : un.storage.archive.xz.lz.LZEncoder
Extends/Implements : -
Subclasses : -

/*
LZEncoder

Authors: Lasse Collin
Igor Pavlov

This file has been put into the public domain.
You can do whatever you want with this file.


Variables : MF_HC4, MF_BT4, matchLenMax, niceLen, buf, readPos
Functions : normalize, getMemoryUsage, getInstance, LZEncoder, setPresetDict, fillWindow, isStarted, setFlushing, setFinishing, hasEnoughData, copyUncompressed, getAvail, getPos, getByte, getByte, getMatchLen, getMatchLen, verifyMatches, movePos, getMatches, skip


public int MF_HC4

public int MF_BT4

int matchLenMax

int niceLen

byte[] buf

int readPos


void normalize (int[] positions, int normalizationOffset)


Gets approximate memory usage of the LZEncoder base structure and
the match finder as kibibytes.
public int getMemoryUsage (int dictSize, int extraSizeBefore, int extraSizeAfter, int matchLenMax, int mf)


Creates a new LZEncoder.


@param dictSize dictionary size

@param extraSizeBefore
number of bytes to keep available in the
history in addition to dictSize

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

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

@param matchLenMax don't test for matches longer than
matchLenMax bytes

@param mf match finder ID

@param depthLimit match finder search depth limit

public LZEncoder getInstance (int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax, int mf, int depthLimit)


Creates a new LZEncoder. See getInstance.
void LZEncoder (int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax)


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.
public void setPresetDict (int dictSize, byte[] presetDict)


Copies new data into the LZEncoder's buffer.
public int fillWindow (byte[] in, int off, int len)


Returns true if at least one byte has already been run through
the match finder.
public boolean isStarted ()


Marks that all the input needs to be made available in
the encoded output.
public void setFlushing ()


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


Tests if there is enough input available to let the caller encode
at least one more byte.
public boolean hasEnoughData (int alreadyReadLen)

public void copyUncompressed (OutputStream out, int backward, int len)


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.

public int getAvail ()


Gets the lowest four bits of the absolute offset of the current byte.
Bits other than the lowest four are undefined.
public int getPos ()


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).

public int getByte (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.
public int getByte (int forward, int backward)


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


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


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.

@param matches return value from getMatches

@return true if matches are valid, false if match finder is broken
public boolean verifyMatches (Matches matches)


Moves to the next byte, checks if there is enough input available,
and returns the amount of input available.
param   requiredForFlushing
minimum number of available bytes when
flushing; encoding may be continued with
new input after flushing
param   requiredForFinishing
minimum number of available bytes when
finishing; encoding must not be continued
after finishing or the match finder state
may be corrupt
return   the number of bytes available or zero if there
is not enough input available
int movePos (int requiredForFlushing, int requiredForFinishing)


Runs match finder for the next byte and returns the matches found.
public Matches getMatches ()


Skips the given number of bytes in the match finder.
public void skip (int len)