- java.lang.Object
-
- com.pervasive.datarush.tokens.scalar.BinaryDataUtil
-
public class BinaryDataUtil extends Object
Utilities for working with binary data.
-
-
Constructor Summary
Constructors Constructor Description BinaryDataUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compare(byte[] lhs, byte[] rhs)
Compares two byte arrays.static byte[]
copy(byte[] data)
Creates a copy of the specified byte array.static byte[]
copy(byte[] data, int offset, int length)
Creates a copy of a subsequence of the specified byte array.static byte[]
parseHexBytes(String value)
Converts the given hexadecimal string value into a binary value.static String
toHexString(byte[] value)
Converts the given byte array into a string representing the hex values of each byte.
-
-
-
Method Detail
-
copy
public static byte[] copy(byte[] data)
Creates a copy of the specified byte array.- Parameters:
data
- the byte array to copy- Returns:
null
if the input wasnull
, otherwise a copy of the input array
-
copy
public static byte[] copy(byte[] data, int offset, int length)
Creates a copy of a subsequence of the specified byte array.- Parameters:
data
- the byte array to copyoffset
- the initial position of the subsequence in the arraylength
- the length of the subsequence- Returns:
null
if the input wasnull
, otherwise a copy of the subsequence
-
toHexString
public static String toHexString(byte[] value)
Converts the given byte array into a string representing the hex values of each byte.- Parameters:
value
- binary value to convert- Returns:
- a hexadecimal string encoding the binary value.
If the value was
null
, the empty string ("") is returned.
-
parseHexBytes
public static byte[] parseHexBytes(String value)
Converts the given hexadecimal string value into a binary value. The string must contain only value hexadecimal characters. A pair of text characters is required for each byte of output, although the first byte may be represented by only one character if the high nibble is zero. This is handled by filling in with a zero character.- Parameters:
value
- String value to convert- Returns:
- the
byte[]
encoded by the string.null
is returned, if the encoding string isnull
. - Throws:
DRException
- if the input is not a valid hexadecimal string
-
compare
public static int compare(byte[] lhs, byte[] rhs)
Compares two byte arrays. Comparison is performed byte-by-byte until either the bytes are unequal or one array has no more bytes, in which case the array with no more bytes is considered lesser.- Parameters:
lhs
- Left hand side valuerhs
- Right hand side value- Returns:
- -1, 0 or 1 indicating less than, equal to, or greater than, respectively
-
-