Enum BinaryUtils

    • Method Detail

      • values

        public static BinaryUtils[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (BinaryUtils c : BinaryUtils.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static BinaryUtils valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • convertBytesToHexString

        public static String convertBytesToHexString​(@Nullable
                                                     byte[] data)
        Converts an array of bytes into a String of hexadecimal characters (0 - F).
        Parameters:
        data - An array of bytes to convert to a String.
        Returns:
        A hexadecimal String representation of the data.
      • convertHexStringToBytes

        public static byte[] convertHexStringToBytes​(String hex)
        Converts a hexadecimal String (such as one generated by the convertBytesToHexString(byte[]) method) into an array of bytes.
        Parameters:
        hex - The hexadecimal String to be converted into an array of bytes.
        Returns:
        An array of bytes that.
      • convertHexStringToBytes

        public static void convertHexStringToBytes​(String hex,
                                                   byte[] destination,
                                                   int offset)
        Converts a hexadecimal String (such as one generated by the convertBytesToHexString(byte[]) method) into an array of bytes.
        Parameters:
        hex - The hexadecimal String to be converted into an array of bytes.
        destination - the array to write to
        offset - the index to start writing
      • convertBytesToInt

        public static int convertBytesToInt​(byte[] bytes,
                                            int offset)
        Take four bytes from the specified position in the specified block and convert them into a 32-bit int, using the big-endian convention.
        Parameters:
        bytes - The data to read from.
        offset - The position to start reading the 4-byte int from.
        Returns:
        The 32-bit integer represented by the four bytes.
      • convertBytesToInts

        public static int[] convertBytesToInts​(byte[] bytes)
        Convert an array of bytes into an array of ints. 4 bytes from the input data map to a single int in the output data.
        Parameters:
        bytes - The data to read from.
        Returns:
        An array of 32-bit integers constructed from the data.
        Since:
        1.1
      • convertBytesToLong

        public static long convertBytesToLong​(byte[] bytes,
                                              int offset)
        Take eight bytes from the specified position in the specified block and convert them into a long, using the big-endian convention.
        Parameters:
        bytes - The data to read from.
        offset - The position to start reading the long from.
        Returns:
        The 32-bit integer represented by the eight bytes.
      • convertLongToBytes

        public static byte[] convertLongToBytes​(long input)
        Converts a long to an array of bytes.

        The returned array will be reused on subsequent calls to this method from the same thread, so a defensive copy may be necessary.

        Parameters:
        input - a long.
        Returns:
        an array of 8 bytes containing the long's value in big-endian order.
      • convertLongToBytes

        public static void convertLongToBytes​(long input,
                                              byte[] output,
                                              int offset)
        Unpacks a long into an existing byte array in big-endian order.
        Parameters:
        input - a long.
        output - the array
        offset - the index to write the first (most significant) byte.
      • convertIntToBytes

        public static void convertIntToBytes​(int input,
                                             byte[] output,
                                             int offset)
        Writes an int to 4 cells of a byte array.
        Parameters:
        input - the int to write
        output - the array to write to
        offset - the first index to write to
      • convertIntToBytes

        public static byte[] convertIntToBytes​(int input)
        Convert an int to an array of 4 bytes.

        The returned array will be reused on subsequent calls to this method from the same thread, so a defensive copy may be necessary.

        Parameters:
        input - an int.
        Returns:
        an array of 4 bytes containing the int's value in big-endian order.