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

public abstract Class Codec

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.commons.compress.harmony.pack200.PopulationCodec, org.apache.commons.compress.harmony.pack200.RunCodec, org.apache.commons.compress.harmony.pack200.BHSDCodec
Imports
java.io.IOException, .InputStream, org.apache.commons.io.input.BoundedInputStream

A Codec allows a sequence of bytes to be decoded into integer values (or vice versa).

There are a number of standard Codecs (UDELTA5, UNSIGNED5, BYTE1, CHAR3) that are used in the implementation of many bands; but there are a variety of other ones, and indeed the specification assumes that other combinations of values can result in more specific and efficient formats. There are also a sequence of canonical encodings defined by the Pack200 specification, which allow a Codec to be referred to by canonical number. CodecEncoding#getCodec(int, InputStream, Codec))

Field Summary

Modifier and TypeField and Description
public static final BHSDCodec
BCI5

BCI5 = (5,4): Used for storing branching information in bytecode.

public static final BHSDCodec
BRANCH5

BRANCH5 = (5,4,2): Used for storing branching information in bytecode.

public static final BHSDCodec
BYTE1

BYTE1 = (1,256): Used for storing plain bytes.

public static final BHSDCodec
CHAR3

CHAR3 = (3,128): Used for storing text (UTF-8) strings.

public static final BHSDCodec
DELTA5

DELTA5 = (5,64,1,1): Used for the majority of numerical codings where there is a correlated sequence of signed values.

public int
public static final BHSDCodec
MDELTA5

MDELTA5 = (5,64,2,1): Used for the majority of numerical codings where there is a correlated sequence of signed values, but where most of them are expected to be non-negative.

public static final BHSDCodec
SIGNED5

SIGNED5 = (5,64,1): Used for small signed values.

public static final BHSDCodec
UDELTA5

UDELTA5 = (5,64,0,1): Used for the majority of numerical codings where there is a correlated sequence of unsigned values.

public static final BHSDCodec
UNSIGNED5

UNSIGNED5 = (5,64): Used for small unsigned values.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv int
check(final int n, final InputStream in)

public abstract int

Returns:

the value as a long
decode
(InputStream
the input stream to read from
in
)

Decodes a sequence of bytes from the given input stream, returning the value as a long.

public abstract int

Returns:

the value as a long
decode
(InputStream
the input stream to read from
in
,
long
the previous value read, which must be supplied if the codec is a delta encoding
last
)

Decodes a sequence of bytes from the given input stream, returning the value as a long.

public int[]

Returns:

an array of int values corresponding to values decoded
decodeInts
(final int
the number of values to decode
n
,
final InputStream
the input stream to read from
in
)

Decodes a sequence of n values from in.

public int[]

Returns:

an array of int values corresponding to values decoded, with firstValue as the first value in the array.
decodeInts
(final int
the number of values to decode
n
,
final InputStream
the input stream to read from
in
,
final int
the first value in the band if it has already been read
firstValue
)

Decodes a sequence of n values from in.

public abstract byte[]

Returns:

the encoded bytes
encode
(int
the value to encode
value
)

Encodes a single value into a sequence of bytes.

public abstract byte[]

Returns:

the encoded bytes
encode
(int
the value to encode
value
,
int
the previous value encoded (for delta encodings)
last
)

Encodes a single value into a sequence of bytes.

public byte[]

Returns:

byte[] encoded bytes
encode
(final int[]
the values to encode
ints
)

Encodes a sequence of integers into a byte array

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BCI5back to summary
public static final BHSDCodec BCI5

BCI5 = (5,4): Used for storing branching information in bytecode.

BRANCH5back to summary
public static final BHSDCodec BRANCH5

BRANCH5 = (5,4,2): Used for storing branching information in bytecode.

BYTE1back to summary
public static final BHSDCodec BYTE1

BYTE1 = (1,256): Used for storing plain bytes.

CHAR3back to summary
public static final BHSDCodec CHAR3

CHAR3 = (3,128): Used for storing text (UTF-8) strings. This isn't quite the same as UTF-8, but has similar properties; ASCII characters < 127 are stored in a single byte.

DELTA5back to summary
public static final BHSDCodec DELTA5

DELTA5 = (5,64,1,1): Used for the majority of numerical codings where there is a correlated sequence of signed values.

lastBandLengthback to summary
public int lastBandLength
MDELTA5back to summary
public static final BHSDCodec MDELTA5

MDELTA5 = (5,64,2,1): Used for the majority of numerical codings where there is a correlated sequence of signed values, but where most of them are expected to be non-negative.

SIGNED5back to summary
public static final BHSDCodec SIGNED5

SIGNED5 = (5,64,1): Used for small signed values.

UDELTA5back to summary
public static final BHSDCodec UDELTA5

UDELTA5 = (5,64,0,1): Used for the majority of numerical codings where there is a correlated sequence of unsigned values.

UNSIGNED5back to summary
public static final BHSDCodec UNSIGNED5

UNSIGNED5 = (5,64): Used for small unsigned values.

Constructor Detail

Codecback to summary
public Codec()

Method Detail

checkback to summary
pack-priv int check(final int n, final InputStream in) throws Pack200Exception
decodeback to summary
public abstract int decode(InputStream in) throws IOException, Pack200Exception

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

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 abstract int decode(InputStream in, long last) throws IOException, Pack200Exception

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

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

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

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, final int firstValue) throws IOException, Pack200Exception

Decodes a sequence of n values from in.

Parameters
n:int

the number of values to decode

in:InputStream

the input stream to read from

firstValue:int

the first value in the band if it has already been read

Returns:int[]

an array of int values corresponding to values decoded, with firstValue as the first value in the array.

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 abstract byte[] encode(int value) throws Pack200Exception

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

Exceptions
Pack200Exception:
TODO
encodeback to summary
public abstract byte[] encode(int value, int last) throws Pack200Exception

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

Exceptions
Pack200Exception:
TODO
encodeback to summary
public byte[] encode(final int[] ints) throws Pack200Exception

Encodes a sequence of integers into a byte array

Parameters
ints:int[]

the values to encode

Returns:byte[]

byte[] encoded bytes

Exceptions
Pack200Exception:
if there is a problem encoding any of the values