Top Description Fields Constructors Methods
org.apache.commons.compress.harmony.pack200

public Class PopulationCodec

extends Codec
Class Inheritance
Imports
java.io.IOException, .InputStream, java.util.Arrays

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

Modifier and TypeField and Description
private int[]
private final Codec
private int
l

private Codec
private final Codec
Inherited from org.apache.commons.compress.harmony.pack200.Codec:
BCI5BRANCH5BYTE1CHAR3DELTA5lastBandLengthMDELTA5SIGNED5UDELTA5UNSIGNED5

Constructor Summary

AccessConstructor and Description
public
PopulationCodec(final Codec favouredCodec, final Codec tokenCodec, final Codec unvafouredCodec)

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

Method Summary

Modifier and TypeMethod and Description
public int
decode(final InputStream
the input stream to read from
in
)

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.decode.

Decodes a sequence of bytes from the given input stream, returning the value as a long.
public int
decode(final InputStream
the input stream to read from
in
,
final long
the previous value read, which must be supplied if the codec is a delta encoding
last
)

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.decode.

Decodes a sequence of bytes from the given input stream, returning the value as a long.
public int[]
decodeInts(final int
the number of values to decode
n
,
final InputStream
the input stream to read from
in
)

Overrides org.apache.commons.compress.harmony.pack200.Codec.decodeInts.

Decodes a sequence of n values from in.
public byte[]
encode(final int
the value to encode
value
)

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.encode.

Encodes a single value into a sequence of bytes.
public byte[]
encode(final int
the value to encode
value
,
final int
the previous value encoded (for delta encodings)
last
)

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.encode.

Encodes a single value into a sequence of bytes.
public byte[]
encode(final int[] favoured, final int[] tokens, final int[] unfavoured)

public int[]
public Codec
public Codec
public Codec
Inherited from org.apache.commons.compress.harmony.pack200.Codec:
checkdecodeIntsencode

Field Detail

favouredback to summary
private int[] favoured
favouredCodecback to summary
private final Codec favouredCodec
lback to summary
private int l
tokenCodecback to summary
private Codec tokenCodec
unfavouredCodecback to summary
private final Codec unfavouredCodec

Constructor Detail

PopulationCodecback to summary
public PopulationCodec(final Codec favouredCodec, final Codec tokenCodec, final Codec unvafouredCodec)
PopulationCodecback to summary
public PopulationCodec(final Codec favouredCodec, final int l, final Codec unfavouredCodec)

Method Detail

decodeback to summary
public int decode(final InputStream in) throws IOException, Pack200Exception

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.decode.

Doc from org.apache.commons.compress.harmony.pack200.Codec.decode.

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

Parameters
in:InputStream

the input stream to read from

Returns:int

the value as a long

Annotations
@Override
Exceptions
IOException:
if there is a problem reading from the underlying input stream
Pack200Exception:
if the encoding is a delta encoding
decodeback to summary
public int decode(final InputStream in, final long last) throws IOException, Pack200Exception

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.decode.

Doc from org.apache.commons.compress.harmony.pack200.Codec.decode.

Decodes 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
}
Parameters
in:InputStream

the input stream to read from

last:long

the previous value read, which must be supplied if the codec is a delta encoding

Returns:int

the value as a long

Annotations
@Override
Exceptions
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
decodeIntsback to summary
public int[] decodeInts(final int n, final InputStream in) throws IOException, Pack200Exception

Overrides org.apache.commons.compress.harmony.pack200.Codec.decodeInts.

Doc from org.apache.commons.compress.harmony.pack200.Codec.decodeInts.

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.

Parameters
n:int

the number of values to decode

in:InputStream

the input stream to read from

Returns:int[]

an array of int values corresponding to values decoded

Annotations
@Override
Exceptions
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
encodeback to summary
public byte[] encode(final int value) throws Pack200Exception

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.encode.

Doc from org.apache.commons.compress.harmony.pack200.Codec.encode.

Encodes a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.

Parameters
value:int

the value to encode

Returns:byte[]

the encoded bytes

Annotations
@Override
Exceptions
Pack200Exception:
TODO
encodeback to summary
public byte[] encode(final int value, final int last) throws Pack200Exception

Implements abstract org.apache.commons.compress.harmony.pack200.Codec.encode.

Doc from org.apache.commons.compress.harmony.pack200.Codec.encode.

Encodes a single value into a sequence of bytes.

Parameters
value:int

the value to encode

last:int

the previous value encoded (for delta encodings)

Returns:byte[]

the encoded bytes

Annotations
@Override
Exceptions
Pack200Exception:
TODO
encodeback to summary
public byte[] encode(final int[] favoured, final int[] tokens, final int[] unfavoured) throws Pack200Exception
getFavouredback to summary
public int[] getFavoured()
getFavouredCodecback to summary
public Codec getFavouredCodec()
getTokenCodecback to summary
public Codec getTokenCodec()
getUnfavouredCodecback to summary
public Codec getUnfavouredCodec()