Package io.permazen.util
Class ByteUtil
java.lang.Object
io.permazen.util.ByteUtil
ByteData manipulation utilities.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteDatagetKeyAfterPrefix(ByteData prefix) Get the first key that would be greater than the given key in unsigned lexicographic ordering and that does not have the given key as a prefix.static ByteDatagetNextKey(ByteData key) Get the next key greater than the given key in unsigned lexicographic ordering.static booleanisConsecutive(ByteData key1, ByteData key2) Determine whetherkey2is the next key afterkey1.static ByteDataDetermine the larger of two byte strings when compared lexicographically using unsigned values.static ByteDataDetermine the smaller of two byte strings when compared lexicographically using unsigned values.static intreadInt(ByteData.Reader reader) Read anintas four big-endian bytes.static longreadLong(ByteData.Reader reader) Read alongas eight big-endian bytes.static StringConvert byte data into a string of hex digits, or"null"for null..static voidwriteInt(ByteData.Writer writer, int value) Write anintas four big-endian bytes.static voidwriteLong(ByteData.Writer writer, long value) Write alongas eight big-endian bytes.
-
Field Details
-
STRING_CONVERTER
-
-
Method Details
-
min
Determine the smaller of two byte strings when compared lexicographically using unsigned values.- Parameters:
b1- first byte stringb2- second byte string- Returns:
b1ifb1 <= b2, otherwiseb2- Throws:
NullPointerException- ifb1orb2is null
-
max
Determine the larger of two byte strings when compared lexicographically using unsigned values.- Parameters:
b1- first byte stringb2- second byte string- Returns:
b1ifb1 >= b2, otherwiseb2- Throws:
NullPointerException- ifb1orb2is null
-
getNextKey
Get the next key greater than the given key in unsigned lexicographic ordering.This creates a new key simply by appending a
0x00byte to the data contained in the given key.- Parameters:
key- previous key- Returns:
- next key after
key - Throws:
NullPointerException- ifkeyis null
-
isConsecutive
Determine whetherkey2is the next key afterkey1.- Parameters:
key1- first keykey2- second key- Returns:
- true if
key2immediately followskey1 - Throws:
NullPointerException- if either parameter is null
-
getKeyAfterPrefix
Get the first key that would be greater than the given key in unsigned lexicographic ordering and that does not have the given key as a prefix.- Parameters:
prefix- lower bound prefix key- Returns:
- next key not having
prefixas a prefix - Throws:
IllegalArgumentException- ifprefixhas zero lengthIllegalArgumentException- ifprefixcontains only0xffbytesNullPointerException- ifprefixis null
-
readInt
Read anintas four big-endian bytes.- Parameters:
reader- input- Returns:
- decoded integer
- Throws:
IndexOutOfBoundsException- if less than four bytes remain inreaderNullPointerException- ifreaderis null- See Also:
-
writeInt
Write anintas four big-endian bytes.- Parameters:
writer- byte destinationvalue- value to write- Throws:
NullPointerException- ifwriteris null- See Also:
-
readLong
Read alongas eight big-endian bytes.- Parameters:
reader- input- Returns:
- decoded long
- Throws:
IndexOutOfBoundsException- if less than eight bytes remain inreader- See Also:
-
writeLong
Write alongas eight big-endian bytes.- Parameters:
writer- byte destinationvalue- value to write- Throws:
NullPointerException- ifwriteris null- See Also:
-
toString
Convert byte data into a string of hex digits, or"null"for null..- Parameters:
data- byte data- Returns:
- string encoding of
data, or"null"ifdatais null - See Also:
-