Package io.permazen.util
Class ByteUtil
java.lang.Object
io.permazen.util.ByteUtil
ByteData
manipulation utilities.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteData
getKeyAfterPrefix
(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 ByteData
getNextKey
(ByteData key) Get the next key greater than the given key in unsigned lexicographic ordering.static boolean
isConsecutive
(ByteData key1, ByteData key2) Determine whetherkey2
is the next key afterkey1
.static ByteData
Determine the larger of two byte strings when compared lexicographically using unsigned values.static ByteData
Determine the smaller of two byte strings when compared lexicographically using unsigned values.static int
readInt
(ByteData.Reader reader) Read anint
as four big-endian bytes.static long
readLong
(ByteData.Reader reader) Read along
as eight big-endian bytes.static String
Convert byte data into a string of hex digits, or"null"
for null..static void
writeInt
(ByteData.Writer writer, int value) Write anint
as four big-endian bytes.static void
writeLong
(ByteData.Writer writer, long value) Write along
as 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:
b1
ifb1 <= b2
, otherwiseb2
- Throws:
NullPointerException
- ifb1
orb2
is null
-
max
Determine the larger of two byte strings when compared lexicographically using unsigned values.- Parameters:
b1
- first byte stringb2
- second byte string- Returns:
b1
ifb1 >= b2
, otherwiseb2
- Throws:
NullPointerException
- ifb1
orb2
is null
-
getNextKey
Get the next key greater than the given key in unsigned lexicographic ordering.This creates a new key simply by appending a
0x00
byte to the data contained in the given key.- Parameters:
key
- previous key- Returns:
- next key after
key
- Throws:
NullPointerException
- ifkey
is null
-
isConsecutive
Determine whetherkey2
is the next key afterkey1
.- Parameters:
key1
- first keykey2
- second key- Returns:
- true if
key2
immediately 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
prefix
as a prefix - Throws:
IllegalArgumentException
- ifprefix
has zero lengthIllegalArgumentException
- ifprefix
contains only0xff
bytesNullPointerException
- ifprefix
is null
-
readInt
Read anint
as four big-endian bytes.- Parameters:
reader
- input- Returns:
- decoded integer
- Throws:
IndexOutOfBoundsException
- if less than four bytes remain inreader
NullPointerException
- ifreader
is null- See Also:
-
writeInt
Write anint
as four big-endian bytes.- Parameters:
writer
- byte destinationvalue
- value to write- Throws:
NullPointerException
- ifwriter
is null- See Also:
-
readLong
Read along
as eight big-endian bytes.- Parameters:
reader
- input- Returns:
- decoded long
- Throws:
IndexOutOfBoundsException
- if less than eight bytes remain inreader
- See Also:
-
writeLong
Write along
as eight big-endian bytes.- Parameters:
writer
- byte destinationvalue
- value to write- Throws:
NullPointerException
- ifwriter
is 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"
ifdata
is null - See Also:
-