LZEncoder
Date: 2017-02-08

org.tukaani.xz.lz

## Class LZEncoder

- java.lang.Object
- - org.tukaani.xz.lz.LZEncoder

-     public abstract class LZEncoder
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `MF_BT4`
    `static int` | `MF_HC4`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `copyUncompressed(java.io.OutputStream out, int backward, int len)`
    `int` | `fillWindow(byte[] in, int off, int len)` Copies new data into the LZEncoder's buffer.
    `int` | `getAvail()` Get the number of bytes available, including the current byte.
    `int` | `getByte(int backward)` Gets the byte from the given backward offset.
    `int` | `getByte(int forward, int backward)` Gets the byte from the given forward minus backward offset.
    `static LZEncoder` | `getInstance(int dictSize, int extraSizeBefore, int extraSizeAfter, int niceLen, int matchLenMax, int mf, int depthLimit)` Creates a new LZEncoder.
    `abstract Matches` | `getMatches()` Runs match finder for the next byte and returns the matches found.
    `int` | `getMatchLen(int dist, int lenLimit)` Get the length of a match at the given distance.
    `int` | `getMatchLen(int forward, int dist, int lenLimit)` Get the length of a match at the given distance and forward offset.
    `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.
    `int` | `getPos()` Gets the lowest four bits of the absolute offset of the current byte.
    `boolean` | `hasEnoughData(int alreadyReadLen)` Tests if there is enough input available to let the caller encode at least one more byte.
    `boolean` | `isStarted()` Returns true if at least one byte has already been run through the match finder.
    `void` | `setFinishing()` Marks that there is no more input remaining.
    `void` | `setFlushing()` Marks that all the input needs to be made available in the encoded output.
    `void` | `setPresetDict(int dictSize, byte[] presetDict)` Sets a preset dictionary.
    `abstract void` | `skip(int len)` Skips the given number of bytes in the match finder.
    `boolean` | `verifyMatches(Matches matches)` Verifies that the matches returned by the match finder are valid.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MF_HC4

          public static final int MF_HC4

      See Also:
        Constant Field Values

    - #### MF_BT4

          public static final int MF_BT4

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getMemoryUsage

          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.

    - #### getInstance

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

      Creates a new LZEncoder.

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

    - #### setPresetDict

          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.

    - #### fillWindow

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

      Copies new data into the LZEncoder's buffer.

    - #### isStarted

          public boolean isStarted()

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

    - #### setFlushing

          public void setFlushing()

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

    - #### setFinishing

          public void setFinishing()

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

    - #### hasEnoughData

          public boolean hasEnoughData(int alreadyReadLen)

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

    - #### copyUncompressed

          public void copyUncompressed(java.io.OutputStream out,
                              int backward,
                              int len)
                                throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### getAvail

          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.

    - #### getPos

          public int getPos()

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

    - #### getByte

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

    - #### getByte

          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.

    - #### getMatchLen

          public int getMatchLen(int dist,
                        int lenLimit)

      Get the length of a match at the given distance.
      Parameters:
        `dist` - zero-based distance of the match to test
        `lenLimit` - don't test for a match longer than this
      Returns:
        length of the match; it is in the range [0, lenLimit]

    - #### getMatchLen

          public int getMatchLen(int forward,
                        int dist,
                        int lenLimit)

      Get the length of a match at the given distance and forward offset.
      Parameters:
        `forward` - forward offset
        `dist` - zero-based distance of the match to test
        `lenLimit` - don't test for a match longer than this
      Returns:
        length of the match; it is in the range [0, lenLimit]

    - #### verifyMatches

          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` - return value from `getMatches`
      Returns:
        true if matches are valid, false if match finder is broken

    - #### getMatches

          public abstract Matches getMatches()

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

    - #### skip

          public abstract void skip(int len)

      Skips the given number of bytes in the match finder.