public class ByteMoveToFront extends Object
This object is not thread safe. Clients must provide external synchronization if they are to use it from several concurrent threads.
IntMoveToFront
Constructor and Description |
---|
ByteMoveToFront(byte[] alphabet)
Create a byte MTF encoder/decoder that transforms bytes using the
supplied initial alphabet.
|
ByteMoveToFront(int minValue,
int maxValue)
Create a byte MTF encoder/decoder that transforms bytes in the range
between
minValue and maxValue . |
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] in,
byte[] out)
Decode an array of bytes and update the MTF alphabet.
|
byte |
decode(int index)
Decode a single byte and update the MTF alphabet.
|
byte[] |
encode(byte[] in,
byte[] out)
Encode the bytes in
in and store them in the array out . |
public ByteMoveToFront(int minValue, int maxValue) throws IndexOutOfBoundsException
minValue
and maxValue
.
The initial alphabet of the transformer will be minValue …
maxValue
.
minValue
- The start value of the range. This should be an unsigned
byte in the range 0 to 254.maxValue
- The end value of the range. This should be an unsigned
byte in the range 1 to 255.IndexOutOfBoundsException
- If the min and/or the max values are
not unsigned bytes or if the min value is equal to or greater than the
max value.public ByteMoveToFront(byte[] alphabet)
alphabet
- The initial alphabet. This byte array is not
copied by this method and it will be modified by encoding or decoding
operations.public byte[] encode(byte[] in, byte[] out) throws ArrayIndexOutOfBoundsException, IllegalArgumentException
in
and store them in the array out
.
The MTF alphabet is also updated by this method.in
- The bytes to encode.out
- The array to store the encoded bytes in. This array must be at
least as long as in
.out
ArrayIndexOutOfBoundsException
- If any of the bytes in in
are not in the MTF alphabet.IllegalArgumentException
- If the out
array is too short.public byte decode(int index)
index
- The index in the MTF alphabet for the byte.public byte[] decode(byte[] in, byte[] out) throws ArrayIndexOutOfBoundsException, IllegalArgumentException
out
.in
- The bytes to decode.out
- The array to store the decoded bytes in. This array must be at
least as long as in
.out
ArrayIndexOutOfBoundsException
- If any of the bytes in in
are not in the MTF alphabet.IllegalArgumentException
- If out
is too short.