- java.lang.Object
-
- kala.compress.harmony.pack200.Codec
-
- kala.compress.harmony.pack200.RunCodec
-
public class RunCodec extends Codec
A run codec is a grouping of two nested codecs; K values are decoded from the first codec, and the remaining codes are decoded from the remaining codec. Note that since this codec maintains state, the instances are not reusable.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdecode(java.io.InputStream in)Decodes a sequence of bytes from the given input stream, returning the value as a long.intdecode(java.io.InputStream in, long last)Decodes a sequence of bytes from the given input stream, returning the value as a long.int[]decodeInts(int n, java.io.InputStream in)Decodes a sequence ofnvalues fromin.byte[]encode(int value)Encodes a single value into a sequence of bytes.byte[]encode(int value, int last)Encodes a single value into a sequence of bytes.CodecgetACodec()CodecgetBCodec()intgetK()private voidnormalise(int[] band, Codec codecUsed)private intnormalise(int value, Codec codecUsed)java.lang.StringtoString()-
Methods inherited from class kala.compress.harmony.pack200.Codec
check, decodeInts, encode
-
-
-
-
Constructor Detail
-
RunCodec
public RunCodec(int k, Codec aCodec, Codec bCodec) throws Pack200Exception- Throws:
Pack200Exception
-
-
Method Detail
-
decode
public int decode(java.io.InputStream in) throws java.io.IOException, Pack200ExceptionDescription copied from class:CodecDecodes 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:
decodein classCodec- Parameters:
in- the input stream to read from- Returns:
- the value as a long
- Throws:
java.io.IOException- if there is a problem reading from the underlying input streamPack200Exception- if the encoding is a delta encoding
-
decode
public int decode(java.io.InputStream in, long last) throws java.io.IOException, Pack200ExceptionDescription copied from class:CodecDecodes 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:
decodein classCodec- 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:
java.io.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
public int[] decodeInts(int n, java.io.InputStream in) throws java.io.IOException, Pack200ExceptionDescription copied from class:CodecDecodes a sequence ofnvalues 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.- Overrides:
decodeIntsin classCodec- Parameters:
n- the number of values to decodein- the input stream to read from- Returns:
- an array of
intvalues corresponding to values decoded - Throws:
java.io.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
public byte[] encode(int value) throws Pack200ExceptionDescription copied from class:CodecEncodes a single value into a sequence of bytes. Note that this method can only be used for non-delta encodings.- Specified by:
encodein classCodec- Parameters:
value- the value to encode- Returns:
- the encoded bytes
- Throws:
Pack200Exception- TODO
-
encode
public byte[] encode(int value, int last) throws Pack200ExceptionDescription copied from class:CodecEncodes a single value into a sequence of bytes.- Specified by:
encodein classCodec- Parameters:
value- the value to encodelast- the previous value encoded (for delta encodings)- Returns:
- the encoded bytes
- Throws:
Pack200Exception- TODO
-
getACodec
public Codec getACodec()
-
getBCodec
public Codec getBCodec()
-
getK
public int getK()
-
normalise
private int normalise(int value, Codec codecUsed)
-
normalise
private void normalise(int[] band, Codec codecUsed)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-