Top Inners Fields Constructors Methods
org.tukaani.xz.lzma

public abstract Class LZMAEncoder

extends LZMACoder
Class Inheritance
Known Direct Subclasses
org.tukaani.xz.lzma.LZMAEncoderFast, org.tukaani.xz.lzma.LZMAEncoderNormal
Imports
java.io.IOException, org.tukaani.xz.ArrayCache, org.tukaani.xz.lz.LZEncoder, .Matches, org.tukaani.xz.rangecoder.RangeEncoder

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
pack-priv class

Field Summary

Modifier and TypeField and Description
private static final int
private int
private final int[]
pack-priv int
private static final int
private int
private final int[][]
private final int
private final int[][]
pack-priv final LZMAEncoder.LiteralEncoder
pack-priv final LZEncoder
private static final int
LZMA2_COMPRESSED_LIMIT

LZMA2 chunk is considered full when its compressed size exceeds LZMA2_COMPRESSED_LIMIT.

private static final int
LZMA2_UNCOMPRESSED_LIMIT

LZMA2 chunk is considered full when its uncompressed size exceeds LZMA2_UNCOMPRESSED_LIMIT.

pack-priv final LZMAEncoder.LengthEncoder
public static final int
public static final int
pack-priv final int
private final RangeEncoder
pack-priv int
pack-priv final LZMAEncoder.LengthEncoder
private int
Inherited from org.tukaani.xz.lzma.LZMACoder:
ALIGN_BITSALIGN_MASKALIGN_SIZEDIST_MODEL_ENDDIST_MODEL_STARTDIST_SLOTSDIST_STATESdistAligndistSlotsdistSpecialFULL_DISTANCESisMatchisRepisRep0isRep0LongisRep1isRep2MATCH_LEN_MAXMATCH_LEN_MINPOS_STATES_MAXposMaskREPSrepsstate

Constructor Summary

AccessConstructor and Description
pack-priv
LZMAEncoder(RangeEncoder rc, LZEncoder lz, int lc, int lp, int pb, int dictSize, int niceLen)

Method Summary

Modifier and TypeMethod and Description
public void
encodeForLZMA1()

Compress for LZMA1.

public boolean

Returns:

true if the LZMA2 chunk became full, false otherwise
encodeForLZMA2
()

Compresses for LZMA2.

private boolean
public void
private void
encodeMatch(int dist, int len, int posState)

private void
encodeRepMatch(int rep, int len, int posState)

private boolean
pack-priv int
getAnyMatchPrice(State state, int posState)

pack-priv int
getAnyRepPrice(int anyMatchPrice, State state)

public static int
getDistSlot(int dist)

Gets an integer [0, 63] matching the highest two bits of an integer.

public static LZMAEncoder
getInstance(RangeEncoder rc, int lc, int lp, int pb, int mode, int dictSize, int extraSizeBefore, int niceLen, int mf, int depthLimit, ArrayCache arrayCache)

pack-priv int
getLongRepAndLenPrice(int rep, int len, State state, int posState)

pack-priv int
getLongRepPrice(int anyRepPrice, int rep, State state, int posState)

public LZEncoder
pack-priv int
getMatchAndLenPrice(int normalMatchPrice, int dist, int len, int posState)

pack-priv Matches
public static int
getMemoryUsage(int mode, int dictSize, int extraSizeBefore, int mf)

pack-priv abstract int
getNextSymbol()

Gets the next LZMA symbol.

pack-priv int
getNormalMatchPrice(int anyMatchPrice, State state)

pack-priv int
getShortRepPrice(int anyRepPrice, State state, int posState)

public int
public void
public void
public void
pack-priv void
skip(int len)

private void
private void
pack-priv void
updatePrices()

Updates the lookup tables used for calculating match distance and length prices.

Inherited from org.tukaani.xz.lzma.LZMACoder:
getDistState

Field Detail

ALIGN_PRICE_UPDATE_INTERVALback to summary
private static final int ALIGN_PRICE_UPDATE_INTERVAL
alignPriceCountback to summary
private int alignPriceCount
alignPricesback to summary
private final int[] alignPrices
backback to summary
pack-priv int back
DIST_PRICE_UPDATE_INTERVALback to summary
private static final int DIST_PRICE_UPDATE_INTERVAL
distPriceCountback to summary
private int distPriceCount
distSlotPricesback to summary
private final int[][] distSlotPrices
distSlotPricesSizeback to summary
private final int distSlotPricesSize
fullDistPricesback to summary
private final int[][] fullDistPrices
literalEncoderback to summary
pack-priv final LZMAEncoder.LiteralEncoder literalEncoder
lzback to summary
pack-priv final LZEncoder lz
LZMA2_COMPRESSED_LIMITback to summary
private static final int LZMA2_COMPRESSED_LIMIT

LZMA2 chunk is considered full when its compressed size exceeds LZMA2_COMPRESSED_LIMIT.

The maximum compressed size of a LZMA2 chunk is 64 KiB. A single LZMA symbol might use 20 bytes of space even though it usually takes just one byte or so. Two more bytes are needed for LZMA2 uncompressed chunks (see LZMA2OutputStream.writeChunk). Leave a little safety margin and use 26 bytes.

LZMA2_UNCOMPRESSED_LIMITback to summary
private static final int LZMA2_UNCOMPRESSED_LIMIT

LZMA2 chunk is considered full when its uncompressed size exceeds LZMA2_UNCOMPRESSED_LIMIT.

A compressed LZMA2 chunk can hold 2 MiB of uncompressed data. A single LZMA symbol may indicate up to MATCH_LEN_MAX bytes of data, so the LZMA2 chunk is considered full when there is less space than MATCH_LEN_MAX bytes.

matchLenEncoderback to summary
pack-priv final LZMAEncoder.LengthEncoder matchLenEncoder
MODE_FASTback to summary
public static final int MODE_FAST
MODE_NORMALback to summary
public static final int MODE_NORMAL
niceLenback to summary
pack-priv final int niceLen
rcback to summary
private final RangeEncoder rc
readAheadback to summary
pack-priv int readAhead
repLenEncoderback to summary
pack-priv final LZMAEncoder.LengthEncoder repLenEncoder
uncompressedSizeback to summary
private int uncompressedSize

Constructor Detail

LZMAEncoderback to summary
pack-priv LZMAEncoder(RangeEncoder rc, LZEncoder lz, int lc, int lp, int pb, int dictSize, int niceLen)

Method Detail

encodeForLZMA1back to summary
public void encodeForLZMA1() throws IOException

Compress for LZMA1.

encodeForLZMA2back to summary
public boolean encodeForLZMA2()

Compresses for LZMA2.

Returns:boolean

true if the LZMA2 chunk became full, false otherwise

encodeInitback to summary
private boolean encodeInit() throws IOException
encodeLZMA1EndMarkerback to summary
public void encodeLZMA1EndMarker() throws IOException
encodeMatchback to summary
private void encodeMatch(int dist, int len, int posState) throws IOException
encodeRepMatchback to summary
private void encodeRepMatch(int rep, int len, int posState) throws IOException
encodeSymbolback to summary
private boolean encodeSymbol() throws IOException
getAnyMatchPriceback to summary
pack-priv int getAnyMatchPrice(State state, int posState)
getAnyRepPriceback to summary
pack-priv int getAnyRepPrice(int anyMatchPrice, State state)
getDistSlotback to summary
public static int getDistSlot(int dist)

Gets an integer [0, 63] matching the highest two bits of an integer. This is like bit scan reverse (BSR) on x86 except that this also cares about the second highest bit.

getInstanceback to summary
public static LZMAEncoder getInstance(RangeEncoder rc, int lc, int lp, int pb, int mode, int dictSize, int extraSizeBefore, int niceLen, int mf, int depthLimit, ArrayCache arrayCache)
getLongRepAndLenPriceback to summary
pack-priv int getLongRepAndLenPrice(int rep, int len, State state, int posState)
getLongRepPriceback to summary
pack-priv int getLongRepPrice(int anyRepPrice, int rep, State state, int posState)
getLZEncoderback to summary
public LZEncoder getLZEncoder()
getMatchAndLenPriceback to summary
pack-priv int getMatchAndLenPrice(int normalMatchPrice, int dist, int len, int posState)
getMatchesback to summary
pack-priv Matches getMatches()
getMemoryUsageback to summary
public static int getMemoryUsage(int mode, int dictSize, int extraSizeBefore, int mf)
getNextSymbolback to summary
pack-priv abstract int getNextSymbol()

Gets the next LZMA symbol.

There are three types of symbols: literal (a single byte), repeated match, and normal match. The symbol is indicated by the return value and by the variable back.

Literal: back == -1 and return value is 1. The literal itself needs to be read from lz separately.

Repeated match: back is in the range [0, 3] and the return value is the length of the repeated match.

Normal match: back - REPS (back - 4) is the distance of the match and the return value is the length of the match.

getNormalMatchPriceback to summary
pack-priv int getNormalMatchPrice(int anyMatchPrice, State state)
getShortRepPriceback to summary
pack-priv int getShortRepPrice(int anyRepPrice, State state, int posState)
getUncompressedSizeback to summary
public int getUncompressedSize()
putArraysToCacheback to summary
public void putArraysToCache(ArrayCache arrayCache)
resetback to summary
public void reset()

Overrides org.tukaani.xz.lzma.LZMACoder.reset.

resetUncompressedSizeback to summary
public void resetUncompressedSize()
skipback to summary
pack-priv void skip(int len)
updateAlignPricesback to summary
private void updateAlignPrices()
updateDistPricesback to summary
private void updateDistPrices()
updatePricesback to summary
pack-priv void updatePrices()

Updates the lookup tables used for calculating match distance and length prices. The updating is skipped for performance reasons if the tables haven't changed much since the previous update.

org.tukaani.xz.lzma back to summary

pack-priv Class LZMAEncoder.LengthEncoder

extends LengthCoder
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final int[]
private static final int
PRICE_UPDATE_INTERVAL

The prices are updated after at least PRICE_UPDATE_INTERVAL many lengths have been encoded with the same posState.

private final int[][]
Inherited from org.tukaani.xz.lzma.LZMACoder.LengthCoder:
choicehighHIGH_SYMBOLSlowLOW_SYMBOLSmidMID_SYMBOLS

Constructor Summary

AccessConstructor and Description
pack-priv
LengthEncoder(int pb, int niceLen)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
encode(int len, int posState)

pack-priv int
getPrice(int len, int posState)

pack-priv void
pack-priv void
private void
updatePrices(int posState)

Field Detail

countersback to summary
private final int[] counters
PRICE_UPDATE_INTERVALback to summary
private static final int PRICE_UPDATE_INTERVAL

The prices are updated after at least PRICE_UPDATE_INTERVAL many lengths have been encoded with the same posState.

pricesback to summary
private final int[][] prices

Constructor Detail

LengthEncoderback to summary
pack-priv LengthEncoder(int pb, int niceLen)

Method Detail

encodeback to summary
pack-priv void encode(int len, int posState) throws IOException
getPriceback to summary
pack-priv int getPrice(int len, int posState)
resetback to summary
pack-priv void reset()

Overrides org.tukaani.xz.lzma.LZMACoder.LengthCoder.reset.

updatePricesback to summary
pack-priv void updatePrices()
updatePricesback to summary
private void updatePrices(int posState)
org.tukaani.xz.lzma back to summary

pack-priv Class LZMAEncoder.LiteralEncoder

extends LiteralCoder
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final LZMAEncoder.LiteralEncoder.LiteralSubencoder[]

Constructor Summary

AccessConstructor and Description
pack-priv
LiteralEncoder(int lc, int lp)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
pack-priv int
getPrice(int curByte, int matchByte, int prevByte, int pos, State state)

pack-priv void
Inherited from org.tukaani.xz.lzma.LZMACoder.LiteralCoder:
getSubcoderIndex

Field Detail

subencodersback to summary
private final LZMAEncoder.LiteralEncoder.LiteralSubencoder[] subencoders

Constructor Detail

LiteralEncoderback to summary
pack-priv LiteralEncoder(int lc, int lp)

Method Detail

encodeback to summary
pack-priv void encode() throws IOException
encodeInitback to summary
pack-priv void encodeInit() throws IOException
getPriceback to summary
pack-priv int getPrice(int curByte, int matchByte, int prevByte, int pos, State state)
resetback to summary
pack-priv void reset()
org.tukaani.xz.lzma back to summary

private Class LZMAEncoder.LiteralEncoder.LiteralSubencoder

extends LiteralSubcoder
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv int
getMatchedPrice(int symbol, int matchByte)

pack-priv int
getNormalPrice(int symbol)

Inherited from org.tukaani.xz.lzma.LZMACoder.LiteralCoder.LiteralSubcoder:
reset

Constructor Detail

LiteralSubencoderback to summary
private LiteralSubencoder()

Method Detail

encodeback to summary
pack-priv void encode() throws IOException
getMatchedPriceback to summary
pack-priv int getMatchedPrice(int symbol, int matchByte)
getNormalPriceback to summary
pack-priv int getNormalPrice(int symbol)