public class OrderedCode extends Object
More precisely, suppose:
This class is NOT thread safe.
| Modifier and Type | Field and Description |
|---|---|
static byte |
ESCAPE1 |
static byte[] |
ESCAPE1_SEPARATOR |
static byte |
ESCAPE2 |
static byte |
FF_CHARACTER |
static byte |
INFINITY |
static byte[] |
INFINITY_ENCODED |
static byte |
NULL_CHARACTER |
static byte |
SEPARATOR |
| Constructor and Description |
|---|
OrderedCode()
Creates OrderedCode from scractch.
|
OrderedCode(byte[] encodedByteArray)
Creates OrderedCode from a given encoded byte array.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
getEncodedBytes()
Returns the encoded bytes that represent the current state of the
OrderedCode.
|
boolean |
hasRemainingEncodedBytes()
Returns true if this has more encoded bytes that haven't been read,
false otherwise.
|
byte[] |
readBytes()
Returns the next byte array item from its encoded byte array store and
removes the item from the store.
|
byte[] |
readBytes(int len)
Reads (unencoded)
len bytes. |
boolean |
readInfinity()
Removes INFINITY item from its internal encoded byte array store
if present.
|
long |
readNumIncreasing()
Returns the next long item (encoded in big-endian format via
writeNumIncreasing(long)) from its internal encoded byte array
store and removes the item from the store. |
long |
readSignedNumIncreasing()
Returns the next long item (encoded via
writeSignedNumIncreasing(long)) from its internal encoded byte
array store and removes the item from the store. |
byte[] |
readTrailingBytes()
Returns the trailing byte array item from its internal encoded byte array
store and removes the item from the store.
|
void |
writeBytes(byte[] value)
Adds the given byte array item to the OrderedCode.
|
void |
writeInfinity()
Encodes and appends INFINITY item to its internal encoded byte array
store.
|
void |
writeNumIncreasing(long value)
Encodes the long item, in big-endian format, and appends the result to its
internal encoded byte array store.
|
void |
writeSignedNumIncreasing(long val)
Encodes the long item, in big-endian format, and appends the result to its
internal encoded byte array store.
|
void |
writeTrailingBytes(byte[] value)
Appends the byte array item to its internal encoded byte array
store.
|
public static final byte ESCAPE1
public static final byte NULL_CHARACTER
public static final byte SEPARATOR
public static final byte ESCAPE2
public static final byte INFINITY
public static final byte FF_CHARACTER
public static final byte[] ESCAPE1_SEPARATOR
public static final byte[] INFINITY_ENCODED
public OrderedCode()
public OrderedCode(byte[] encodedByteArray)
For better performance, it uses the input array provided (not a copy). Therefore the input array should not be modified.
public void writeBytes(byte[] value)
It works with the input array, so the input array 'value' should not be modified till the method returns.
value - bytes to be written.readBytes()public void writeNumIncreasing(long value)
Note that the specified long is treated like a uint64, e.g.
new OrderedCode().writeNumIncreasing(-1L).getEncodedBytes()
is greater than
new OrderedCode().writeNumIncreasing(Long.MAX_VALUE).getEncodedBytes().
readNumIncreasing()public void writeSignedNumIncreasing(long val)
Note that the specified long is treated like an int64, i.e.
new OrderedCode().writeNumIncreasing(-1L).getEncodedBytes()
is less than
new OrderedCode().writeNumIncreasing(0L).getEncodedBytes().
readSignedNumIncreasing()public void writeInfinity()
readInfinity()public void writeTrailingBytes(byte[] value)
readBytes(int).
It stores the input array in the store, so the input array 'value' should not be modified.
value - bytes to be written.readTrailingBytes(),
readBytes(int)public byte[] readBytes()
writeBytes(byte[])public long readNumIncreasing()
writeNumIncreasing(long)) from its internal encoded byte array
store and removes the item from the store.writeNumIncreasing(long)public long readSignedNumIncreasing()
writeSignedNumIncreasing(long)) from its internal encoded byte
array store and removes the item from the store.writeSignedNumIncreasing(long)public boolean readInfinity()
writeInfinity()public byte[] readTrailingBytes()
writeTrailingBytes(byte[])public byte[] readBytes(int len)
len bytes.writeTrailingBytes(byte[])public byte[] getEncodedBytes()
NOTE: This method returns OrederedCode's internal array (not a copy) for better performance. Therefore the returned array should not be modified.
public boolean hasRemainingEncodedBytes()