Class BinaryDataUtil


  • public class BinaryDataUtil
    extends Object
    Utilities for working with binary data.
    • Constructor Detail

      • BinaryDataUtil

        public BinaryDataUtil()
    • 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 was null, 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 copy
        offset - the initial position of the subsequence in the array
        length - the length of the subsequence
        Returns:
        null if the input was null, 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 is null.
        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 value
        rhs - Right hand side value
        Returns:
        -1, 0 or 1 indicating less than, equal to, or greater than, respectively