Package org.apache.commons.compress.harmony.pack200

# Class PopulationCodec

java.lang.Object
org.apache.commons.compress.harmony.pack200.Codec
org.apache.commons.compress.harmony.pack200.PopulationCodec

public class PopulationCodec extends Codec
A PopulationCodec is a Codec that is well suited to encoding data that shows statistical or repetitive patterns, containing for example a few numbers which are repeated a lot throughout the set, but not necessarily sequentially.

- ## Field Summary

  ### Fields inherited from class org.apache.commons.compress.harmony.pack200.Codec

  `BCI5, BRANCH5, BYTE1, CHAR3, DELTA5, lastBandLength, MDELTA5, SIGNED5, UDELTA5, UNSIGNED5`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PopulationCodec(Codec favouredCodec, int l, Codec unfavouredCodec)`
  `PopulationCodec(Codec favouredCodec, Codec tokenCodec, Codec unvafouredCodec)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `decode(InputStream in)`
  Decode a sequence of bytes from the given input stream, returning the value as a long.
  `int`
  `decode(InputStream in, long last)`
  Decode a sequence of bytes from the given input stream, returning the value as a long.
  `int[]`
  `decodeInts(int n, InputStream in)`
  Decodes a sequence of `n` values from `in`.
  `byte[]`
  `encode(int value)`
  Encode a single value into a sequence of bytes.
  `byte[]`
  `encode(int[] favoured, int[] tokens, int[] unfavoured)`
  `byte[]`
  `encode(int value, int last)`
  Encode a single value into a sequence of bytes.
  `int[]`
  `getFavoured()`
  `Codec`
  `getFavouredCodec()`
  `Codec`
  `getTokenCodec()`
  `Codec`
  `getUnfavouredCodec()`

  ### Methods inherited from class org.apache.commons.compress.harmony.pack200.Codec

  `decodeInts, encode`

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

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

- ## Constructor Details

  - ### PopulationCodec

    public PopulationCodec(Codec favouredCodec, Codec tokenCodec, Codec unvafouredCodec)

  - ### PopulationCodec

    public PopulationCodec(Codec favouredCodec, int l, Codec unfavouredCodec)

- ## Method Details

  - ### decode

    public int decode(InputStream in) throws IOException, Pack200Exception
    Description copied from class: `Codec`
    Decode a sequence of bytes from the given input stream, returning the value as a long. Note that this method can only be applied for non-delta encodings.
    Specified by:
      `decode` in class `Codec`
    Parameters:
      `in` - the input stream to read from
    Returns:
      the value as a long
    Throws:
      `IOException` - if there is a problem reading from the underlying input stream
      `Pack200Exception` - if the encoding is a delta encoding

  - ### decode

    public int decode(InputStream in, long last) throws IOException, Pack200Exception
    Description copied from class: `Codec`
    Decode a sequence of bytes from the given input stream, returning the value as a long. If this encoding is a delta encoding (d=1) then the previous value must be passed in as a parameter. If it is a non-delta encoding, then it does not matter what value is passed in, so it makes sense for the value to be passed in by default using code similar to:

         long last = 0;
         while (condition) {
             last = codec.decode(in, last);
             // do something with last
         }

    Specified by:
      `decode` in class `Codec`
    Parameters:
      `in` - the input stream to read from
      `last` - the previous value read, which must be supplied if the codec is a delta encoding
    Returns:
      the value as a long
    Throws:
      `IOException` - if there is a problem reading from the underlying input stream
      `Pack200Exception` - if there is a problem decoding the value or that the value is invalid

  - ### decodeInts

    public int[] decodeInts(int n, InputStream in) throws IOException, Pack200Exception
    Description copied from class: `Codec`
    Decodes a sequence of `n` values from `in`. This should probably be used in most cases, since some codecs (such as `PopulationCodec`) only work when the number of values to be read is known.
    Overrides:
      `decodeInts` in class `Codec`
    Parameters:
      `n` - the number of values to decode
      `in` - the input stream to read from
    Returns:
      an array of `int` values corresponding to values decoded
    Throws:
      `IOException` - if there is a problem reading from the underlying input stream
      `Pack200Exception` - if there is a problem decoding the value or that the value is invalid

  - ### encode

    public byte[] encode(int value) throws Pack200Exception
    Description copied from class: `Codec`
    Encode a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.
    Specified by:
      `encode` in class `Codec`
    Parameters:
      `value` - the value to encode
    Returns:
      the encoded bytes
    Throws:
      `Pack200Exception` - TODO

  - ### encode

    public byte[] encode(int value, int last) throws Pack200Exception
    Description copied from class: `Codec`
    Encode a single value into a sequence of bytes.
    Specified by:
      `encode` in class `Codec`
    Parameters:
      `value` - the value to encode
      `last` - the previous value encoded (for delta encodings)
    Returns:
      the encoded bytes
    Throws:
      `Pack200Exception` - TODO

  - ### encode

    public byte[] encode(int[] favoured, int[] tokens, int[] unfavoured) throws Pack200Exception
    Throws:
      `Pack200Exception`

  - ### getFavoured

    public int[] getFavoured()

  - ### getFavouredCodec

    public Codec getFavouredCodec()

  - ### getTokenCodec

    public Codec getTokenCodec()

  - ### getUnfavouredCodec

    public Codec getUnfavouredCodec()