Class Codec
java.lang.Object
org.apache.commons.compress.harmony.pack200.Codec
- Direct Known Subclasses:
BHSDCodec
,PopulationCodec
,RunCodec
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 TypeFieldDescriptionstatic final BHSDCodec
BCI5 = (5,4): Used for storing branching information in bytecode.static final BHSDCodec
BRANCH5 = (5,4,2): Used for storing branching information in bytecode.static final BHSDCodec
BYTE1 = (1,256): Used for storing plain bytes.static final BHSDCodec
CHAR3 = (3,128): Used for storing text (UTF-8) strings.static final BHSDCodec
DELTA5 = (5,64,1,1): Used for the majority of numerical codings where there is a correlated sequence of signed values.int
static final BHSDCodec
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.static final BHSDCodec
SIGNED5 = (5,64,1): Used for small signed values.static final BHSDCodec
UDELTA5 = (5,64,0,1): Used for the majority of numerical codings where there is a correlated sequence of unsigned values.static final BHSDCodec
UNSIGNED5 = (5,64): Used for small unsigned values. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract int
decode
(InputStream in) Decodes a sequence of bytes from the given input stream, returning the value as a long.abstract int
decode
(InputStream in, long last) Decodes a sequence of bytes from the given input stream, returning the value as a long.int[]
decodeInts
(int n, InputStream in) Decodes a sequence ofn
values fromin
.int[]
decodeInts
(int n, InputStream in, int firstValue) Decodes a sequence ofn
values fromin
.abstract byte[]
encode
(int value) Encodes a single value into a sequence of bytes.byte[]
encode
(int[] ints) Encodes a sequence of integers into a byte arrayabstract byte[]
encode
(int value, int last) Encodes a single value into a sequence of bytes.
-
Field Details
-
BCI5
BCI5 = (5,4): Used for storing branching information in bytecode. -
BRANCH5
BRANCH5 = (5,4,2): Used for storing branching information in bytecode. -
BYTE1
BYTE1 = (1,256): Used for storing plain bytes. -
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. -
DELTA5
DELTA5 = (5,64,1,1): Used for the majority of numerical codings where there is a correlated sequence of signed values. -
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. -
SIGNED5
SIGNED5 = (5,64,1): Used for small signed values. -
UDELTA5
UDELTA5 = (5,64,0,1): Used for the majority of numerical codings where there is a correlated sequence of unsigned values. -
UNSIGNED5
UNSIGNED5 = (5,64): Used for small unsigned values. -
lastBandLength
-
-
Constructor Details
-
Codec
public Codec()
-
-
Method Details
-
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
- the input stream to read from- Returns:
- the value as a long
- Throws:
IOException
- if there is a problem reading from the underlying input streamPack200Exception
- if the encoding is a delta encoding
-
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
- the input stream to read fromlast
- 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 streamPack200Exception
- if there is a problem decoding the value or that the value is invalid
-
decodeInts
Decodes a sequence ofn
values fromin
. This should probably be used in most cases, since some codecs (such asPopulationCodec
) only work when the number of values to be read is known.- Parameters:
n
- the number of values to decodein
- 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 streamPack200Exception
- if there is a problem decoding the value or that the value is invalid
-
decodeInts
Decodes a sequence ofn
values fromin
.- Parameters:
n
- the number of values to decodein
- the input stream to read fromfirstValue
- the first value in the band if it has already been read- Returns:
- an array of
int
values corresponding to values decoded, with firstValue as the first value in the array. - Throws:
IOException
- if there is a problem reading from the underlying input streamPack200Exception
- if there is a problem decoding the value or that the value is invalid
-
encode
Encodes a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.- Parameters:
value
- the value to encode- Returns:
- the encoded bytes
- Throws:
Pack200Exception
- TODO
-
encode
Encodes a single value into a sequence of bytes.- Parameters:
value
- the value to encodelast
- the previous value encoded (for delta encodings)- Returns:
- the encoded bytes
- Throws:
Pack200Exception
- TODO
-
encode
Encodes a sequence of integers into a byte array- Parameters:
ints
- the values to encode- Returns:
- byte[] encoded bytes
- Throws:
Pack200Exception
- if there is a problem encoding any of the values
-