com.h3c.util

## Class ByteUtils

- java.lang.Object
- - com.h3c.util.ByteUtils

-     public final class ByteUtils
      extends Object

  Set of utility methods for encoding and decoding information using byte arrays.

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `and(byte[] b, byte[] other)` This method performs a logical AND of the bits in byte array `b` with the `other` array.
    `static void` | `and(byte[] b, byte[] other, int offset)` This method performs a logical AND of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`.
    `static void` | `and(byte[] b, byte[] other, int offset, int length)` This method performs a logical AND of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`.
    `static String` | `byteToHex(byte b)` Returns a two character string representation of the given byte, in hex.
    `static int` | `byteToInt(byte b)` Converts a byte (-128 ..
    `static int` | `countBits(byte[] b)` Counts and returns the number of 1 bits within the specified byte array.
    `static int` | `countBits(byte[] b, int offset)` Counts and returns the number of 1 bits within the specified region of a byte array, starting at the given offset, to the end of the array.
    `static int` | `countBits(byte[] b, int offset, int length)` Counts and returns the number of 1 bits within the specified region of a byte array, starting at the given offset, for 'length' bytes.
    `static String` | `getByteArrayString(byte[] b)` Returns a string representation of the given byte array.
    `static String` | `getByteArrayString(byte[] b, int len)` Returns a string representation of the given byte array.
    `static String` | `getDebugString(String msg, byte[] b)` Helper method to create log string of a byte array.
    `static String` | `getDebugString(String msg, byte[] b, int len)` Creates a string of a byte array suitable for logging.
    `static String` | `getFilteredString(byte[] b)` Returns a 'filtered' string representation of the given byte array:
    `static int` | `getInteger(byte[] b, int offset)` Extracts the integer value from four bytes of a byte array starting at the given offset.
    `static long` | `getLong(byte[] b, int offset)` Extracts the long value from eight bytes of a byte array starting at the given offset.
    `static String` | `getNullTerminatedAscii(byte[] bytes)` Interprets the given array of bytes as a null-terminated ASCII string, and returns that string.
    `static byte[]` | `getPadded64BitBytes(byte[] b)` Examines the given byte array and returns an array that is padded out to a 64 bit boundary.
    `static byte[]` | `getRawBytes(String s)` Helper method to convert the string to an array of bytes (without local replacement).
    `static short` | `getShort(byte[] b, int offset)` Extracts and returns the short value from two bytes of a byte array starting at the given offset.
    `static String` | `getStringFromRawBytes(byte[] bytes)` Interprets the given array of bytes as a UTF-8 encoded string, and returns that string.
    `static int` | `getU16(byte[] b, int offset)` Reads two bytes from the array (at the given offset), interpreting them as an unsigned 16-bit value.
    `static long` | `getU32(byte[] b, int offset)` Reads four bytes from the array (at the given offset), interpreting them as an unsigned 32-bit value.
    `static BigInteger` | `getU64(byte[] b, int offset)` Reads eight bytes from the array (at the given offset), interpreting them as an unsigned 64-bit value.
    `static short` | `getU8(byte[] b, int offset)` Reads a single byte from the array (at the given offset), interpreting it as an unsigned 8-bit value.
    `static String` | `hex(byte[] b)` Generates a hex dump string from the given bytes.
    `static String` | `hex(byte[] b, int offset)` Generates a hex dump string from the specified offset to the end of the given byte array.
    `static String` | `hex(byte[] b, int offset, int length)` Generates a hex dump string from the specified region of the given byte array.
    `static String` | `hexLookupLower(byte b)` Provides a fast lookup of the 2-digit hex string representation for the given byte, using lowercase alpha digits.
    `static String` | `hexLookupUpper(byte b)` Provides a fast lookup of the 2-digit hex string representation for the given byte, using uppercase alpha digits.
    `static String` | `hexWithPrefix(byte[] bytes)` Returns a string representation of a byte array with "0x" prefix.
    `static int` | `indexOf(byte[] b, byte match)` Scans through the specified byte array returning the index of the first byte that matches the given value, or -1 if no match is found.
    `static int` | `indexOf(byte[] b, byte match, int startIndex)` Scans through the specified byte array starting at the given index, returning the index of the first byte that matches the given value, or -1 if no match is found.
    `static int` | `indexOf(byte[] b, byte match, int startIndex, int endIndex)` Scans through the specified byte array starting at the given index, and ending before the given end index, returning the index of the first byte that matches the given value, or -1 if no match is found.
    `static byte` | `intToByte(int i)` Converts an int (0 ..
    `static void` | `not(byte[] b)` This method reverses all the bits (logical NOT) in the given array.
    `static void` | `not(byte[] b, int offset)` This method reverses all the bits (logical NOT) in the given array, from offset to the end of the array.
    `static void` | `not(byte[] b, int offset, int length)` This method reverses all the bits (logical NOT) in the given array for the specified region.
    `static void` | `or(byte[] b, byte[] other)` This method performs a logical OR of the bits in byte array `b` with the `other` array.
    `static void` | `or(byte[] b, byte[] other, int offset)` This method performs a logical OR of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`.
    `static void` | `or(byte[] b, byte[] other, int offset, int length)` This method performs a logical OR of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`.
    `static byte[]` | `parseHex(String asciiHex)` Generates a byte array by parsing the given ascii string of hex characters.
    `static byte[]` | `parseHexWithPrefix(String s)` Helper method to convert the hex string with "0x" prefix to an array of bytes.
    `static void` | `setInteger(byte[] b, int offset, int value)` Populates four bytes of a byte array with the given integer value.
    `static void` | `setInteger(byte[] b, int offset, long value)` Populates four bytes of a byte array with the lower four bytes of the given long value.
    `static void` | `setLong(byte[] b, int offset, long value)` Populates eight bytes of a byte array with the given long value.
    `static void` | `setShort(byte[] b, int offset, int value)` Populates two bytes of a byte array with the lower two bytes of the given integer value.
    `static void` | `setShort(byte[] b, int offset, short value)` Populates two bytes of a byte array with the given short value.
    `static void` | `setU16(byte[] b, int offset, int value)` Populates two bytes of a byte array (at the given offset), with the supplied equivalent unsigned 16-bit value.
    `static void` | `setU32(byte[] b, int offset, long value)` Populates four bytes of a byte array (at the given offset), with the supplied equivalent unsigned 32-bit value.
    `static void` | `setU64(byte[] b, int offset, BigInteger value)` Populates eight bytes of a byte array (at the given offset), with the supplied equivalent unsigned 64-bit value.
    `static void` | `setU8(byte[] b, int offset, short value)` Populates a single byte of a byte array (at the given offset), with the supplied equivalent unsigned 8-bit value.
    `static byte[]` | `slurpBytesFromHexFile(Class<?> c, String baseName)` Reads in a human readable file of hex data and returns it as a byte array.
    `static byte[]` | `slurpBytesFromHexFile(String path, ClassLoader cl)` Reads in a human readable file of hex data and returns it as a byte array.
    `static String` | `toHexArrayString(byte[] bytes)` Returns a string representation of a byte array.
    `static String` | `toHexString(byte[] bytes)` Returns a string representation of the byte array as a hex dump, with spaces inserted to help reading the string.
    `static void` | `xor(byte[] b, byte[] other)` This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array.
    `static void` | `xor(byte[] b, byte[] other, int offset)` This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`.
    `static void` | `xor(byte[] b, byte[] other, int offset, int length)` This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### byteToInt

          public static int byteToInt(byte b)

      Converts a byte (-128 .. 127) to the equivalent int (0 .. 255).
      Parameters:
        `b` - the byte
      Returns:
        the int value

    - #### intToByte

          public static byte intToByte(int i)

      Converts an int (0 .. 255) to the equivalent byte (-128 .. 127)
      Parameters:
        `i` - the int
      Returns:
        the byte value

    - #### getShort

          public static short getShort(byte[] b,
                       int offset)

      Extracts and returns the short value from two bytes of a byte array starting at the given offset.
      Parameters:
        `b` - the byte array from which to extract the short value
        `offset` - the start offset into the byte array
      Returns:
        the short value represented by the two bytes at the given offset

    - #### setShort

          public static void setShort(byte[] b,
                      int offset,
                      short value)

      Populates two bytes of a byte array with the given short value.
      Parameters:
        `b` - the byte array into which to put the short value
        `offset` - the start offset into the byte array
        `value` - the value to be represented by the two bytes at the given offset

    - #### setShort

          public static void setShort(byte[] b,
                      int offset,
                      int value)

      Populates two bytes of a byte array with the lower two bytes of the given integer value.
      Parameters:
        `b` - the byte array into which to put the lower half of the integer value
        `offset` - the start offset into the byte array
        `value` - the value to be represented by the two bytes at the given offset

    - #### getInteger

          public static int getInteger(byte[] b,
                       int offset)

      Extracts the integer value from four bytes of a byte array starting at the given offset.
      Parameters:
        `b` - the byte array from which to extract the integer value
        `offset` - the start offset into the byte array
      Returns:
        the integer value represented by the four bytes at the given offset

    - #### setInteger

          public static void setInteger(byte[] b,
                        int offset,
                        int value)

      Populates four bytes of a byte array with the given integer value.
      Parameters:
        `b` - the byte array into which to put the integer value
        `offset` - the start offset into the byte array
        `value` - the integer value to be represented by the four bytes at the given offset

    - #### setInteger

          public static void setInteger(byte[] b,
                        int offset,
                        long value)

      Populates four bytes of a byte array with the lower four bytes of the given long value.
      Parameters:
        `b` - the byte array into which to put the lower half of the long value
        `offset` - the start offset into the byte array
        `value` - the value to be represented by the four bytes at the given offset

    - #### getLong

          public static long getLong(byte[] b,
                     int offset)

      Extracts the long value from eight bytes of a byte array starting at the given offset.
      Parameters:
        `b` - the byte array from which to extract the long value
        `offset` - the start offset into the byte array
      Returns:
        the long value represented by the eight bytes at the given offset

    - #### setLong

          public static void setLong(byte[] b,
                     int offset,
                     long value)

      Populates eight bytes of a byte array with the given long value.
      Parameters:
        `b` - the byte array into which to put the long value
        `offset` - the start offset into the byte array
        `value` - the long value to be represented by the eight bytes at the given offset

    - #### getU8

          public static short getU8(byte[] b,
                    int offset)

      Reads a single byte from the array (at the given offset), interpreting it as an unsigned 8-bit value.
      Parameters:
        `b` - the byte array from which to read the byte
        `offset` - the start offset into the byte array
      Returns:
        a short value equivalent to the unsigned 8-bit value

    - #### setU8

          public static void setU8(byte[] b,
                   int offset,
                   short value)

      Populates a single byte of a byte array (at the given offset), with the supplied equivalent unsigned 8-bit value.
      Parameters:
        `b` - the byte array into which to write the u8 value
        `offset` - the start offset into the byte array
        `value` - the unsigned value to be converted and inserted
      Throws:
        `IllegalArgumentException` - if value is not 0..2^8-1

    - #### getU16

          public static int getU16(byte[] b,
                   int offset)

      Reads two bytes from the array (at the given offset), interpreting them as an unsigned 16-bit value.
      Parameters:
        `b` - the byte array from which to read
        `offset` - the start offset into the byte array
      Returns:
        an int value equivalent to the unsigned 16-bit value

    - #### setU16

          public static void setU16(byte[] b,
                    int offset,
                    int value)

      Populates two bytes of a byte array (at the given offset), with the supplied equivalent unsigned 16-bit value.
      Parameters:
        `b` - the byte array into which to write the u16 value
        `offset` - the start offset into the byte array
        `value` - the unsigned value to be converted and inserted
      Throws:
        `IllegalArgumentException` - if uv is not 0..2^16-1

    - #### getU32

          public static long getU32(byte[] b,
                    int offset)

      Reads four bytes from the array (at the given offset), interpreting them as an unsigned 32-bit value.
      Parameters:
        `b` - the byte array from which to read
        `offset` - the start offset into the byte array
      Returns:
        a long value equivalent to the unsigned 32-bit value

    - #### setU32

          public static void setU32(byte[] b,
                    int offset,
                    long value)

      Populates four bytes of a byte array (at the given offset), with the supplied equivalent unsigned 32-bit value.
      Parameters:
        `b` - the byte array into which to write the u32 value
        `offset` - the start offset into the byte array
        `value` - the unsigned value to be converted and inserted
      Throws:
        `IllegalArgumentException` - if uv is not 0..2^32-1

    - #### getU64

          public static BigInteger getU64(byte[] b,
                          int offset)

      Reads eight bytes from the array (at the given offset), interpreting them as an unsigned 64-bit value.
      Parameters:
        `b` - the byte array from which to read
        `offset` - the start offset into the byte array
      Returns:
        a BigInteger value equivalent to the unsigned 64-bit value

    - #### setU64

          public static void setU64(byte[] b,
                    int offset,
                    BigInteger value)

      Populates eight bytes of a byte array (at the given offset), with the supplied equivalent unsigned 64-bit value.
      Parameters:
        `b` - the byte array into which to write the u64 value
        `offset` - the start offset into the byte array
        `value` - the unsigned value to be converted and inserted
      Throws:
        `IllegalArgumentException` - if uv is not 0..2^64-1

    - #### indexOf

          public static int indexOf(byte[] b,
                    byte match)

      Scans through the specified byte array returning the index of the first byte that matches the given value, or -1 if no match is found.
      Parameters:
        `b` - the byte array to search
        `match` - the byte value to match
      Returns:
        the index into the byte array of the first byte that matches, or -1 if the match was not found

    - #### indexOf

          public static int indexOf(byte[] b,
                    byte match,
                    int startIndex)

      Scans through the specified byte array starting at the given index, returning the index of the first byte that matches the given value, or -1 if no match is found.
      Parameters:
        `b` - the byte array to search
        `match` - the byte value to match
        `startIndex` - the index into the array from which to start the search (inclusive)
      Returns:
        the index into the byte array of the first byte that matches, or -1 if the match was not found
      Throws:
        `ArrayIndexOutOfBoundsException` - if startIndex is not within array bounds

    - #### indexOf

          public static int indexOf(byte[] b,
                    byte match,
                    int startIndex,
                    int endIndex)

      Scans through the specified byte array starting at the given index, and ending before the given end index, returning the index of the first byte that matches the given value, or -1 if no match is found.
      Parameters:
        `b` - the byte array to search
        `match` - the byte value to match
        `startIndex` - the index into the array from which to start the search (inclusive)
        `endIndex` - the index which designates the end of the searchable area (exclusive)
      Returns:
        the index into the byte array of the first byte that matches, or -1 if the match was not found
      Throws:
        `ArrayIndexOutOfBoundsException` - if startIndex/endIndex attempts access outside the array bounds

    - #### countBits

          public static int countBits(byte[] b)

      Counts and returns the number of 1 bits within the specified byte array.
      Parameters:
        `b` - the byte array from which to count the 1 bits
      Returns:
        the number of 1 bits in the byte array

    - #### countBits

          public static int countBits(byte[] b,
                      int offset)

      Counts and returns the number of 1 bits within the specified region of a byte array, starting at the given offset, to the end of the array.
      Parameters:
        `b` - the byte array from which to count the 1 bits
        `offset` - the start offset into the byte array
      Returns:
        number of 1 bits in the specified region of the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset is not within array bounds

    - #### countBits

          public static int countBits(byte[] b,
                      int offset,
                      int length)

      Counts and returns the number of 1 bits within the specified region of a byte array, starting at the given offset, for 'length' bytes.
      Parameters:
        `b` - the byte array from which to count the 1 bits
        `offset` - the start offset into the byte array
        `length` - the number of bytes to include in the count
      Returns:
        number of 1 bits in the specified region of the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset/length attempts access outside the array bounds

    - #### not

          public static void not(byte[] b)

      This method reverses all the bits (logical NOT) in the given array.
      Parameters:
        `b` - the byte array

    - #### not

          public static void not(byte[] b,
                 int offset)

      This method reverses all the bits (logical NOT) in the given array, from offset to the end of the array.
      Parameters:
        `b` - the byte array
        `offset` - the start offset into the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset is not within array bounds

    - #### not

          public static void not(byte[] b,
                 int offset,
                 int length)

      This method reverses all the bits (logical NOT) in the given array for the specified region.
      Parameters:
        `b` - the byte array
        `offset` - the start offset into the byte array
        `length` - the number of bytes to include in the operation
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset/length attempts access outside the array bounds

    - #### and

          public static void and(byte[] b,
                 byte[] other)

      This method performs a logical AND of the bits in byte array `b` with the `other` array. The result is left in byte array `b`. Note that if the `other` array is shorter than byte array `b`, the "missing" bytes are assumed to be `0xff` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to AND

    - #### and

          public static void and(byte[] b,
                 byte[] other,
                 int offset)

      This method performs a logical AND of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0xff` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to AND
        `offset` - the start offset into the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset is not within array bounds

    - #### and

          public static void and(byte[] b,
                 byte[] other,
                 int offset,
                 int length)

      This method performs a logical AND of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0xff` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to AND
        `offset` - the start offset into the byte array
        `length` - the number of bytes to include in the operation
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset/length attempts access outside the array bounds

    - #### or

          public static void or(byte[] b,
                byte[] other)

      This method performs a logical OR of the bits in byte array `b` with the `other` array. The result is left in byte array `b`. Note that if the `other` array is shorter than byte array `b`, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to OR

    - #### or

          public static void or(byte[] b,
                byte[] other,
                int offset)

      This method performs a logical OR of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to OR
        `offset` - the start offset into the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset is not within array bounds

    - #### or

          public static void or(byte[] b,
                byte[] other,
                int offset,
                int length)

      This method performs a logical OR of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to OR
        `offset` - the start offset into the byte array
        `length` - the number of bytes to include in the operation
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset/length attempts access outside the array bounds

    - #### xor

          public static void xor(byte[] b,
                 byte[] other)

      This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array. The result is left in byte array `b`. Note that if the `other` array is shorter than byte array `b`, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to EXCLUSIVE-OR

    - #### xor

          public static void xor(byte[] b,
                 byte[] other,
                 int offset)

      This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array, from the specified offset to the end of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to EXCLUSIVE-OR
        `offset` - the start offset into the byte array
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset is not within array bounds

    - #### xor

          public static void xor(byte[] b,
                 byte[] other,
                 int offset,
                 int length)

      This method performs a logical EXCLUSIVE-OR of the bits in byte array `b` with the `other` array, for the specified region of byte array `b`. The result is left in byte array `b`. Note that if the `other` array is shorter than the region specified, the "missing" bytes are assumed to be `0x00` resulting in no change to the original array for those byte positions.
      Parameters:
        `b` - the byte array
        `other` - the operand with which to EXCLUSIVE-OR
        `offset` - the start offset into the byte array
        `length` - the number of bytes to include in the operation
      Throws:
        `ArrayIndexOutOfBoundsException` - if offset/length attempts access outside the array bounds

    - #### hex

          public static String hex(byte[] b)

      Generates a hex dump string from the given bytes.
      Parameters:
        `b` - the byte array
      Returns:
        a formatted hex image of the portion of the byte array

    - #### hex

          public static String hex(byte[] b,
                   int offset)

      Generates a hex dump string from the specified offset to the end of the given byte array.
      Parameters:
        `b` - the byte array
        `offset` - the start offset into the byte array
      Returns:
        a formatted hex image of the portion of the byte array

    - #### hex

          public static String hex(byte[] b,
                   int offset,
                   int length)

      Generates a hex dump string from the specified region of the given byte array.
      Parameters:
        `b` - the byte array
        `offset` - the start offset into the byte array
        `length` - the number of bytes to output
      Returns:
        a formatted hex image of the byte array

    - #### hexLookupLower

          public static String hexLookupLower(byte b)

      Provides a fast lookup of the 2-digit hex string representation for the given byte, using lowercase alpha digits.
      Parameters:
        `b` - the byte
      Returns:
        the 2-digit hex representation

    - #### hexLookupUpper

          public static String hexLookupUpper(byte b)

      Provides a fast lookup of the 2-digit hex string representation for the given byte, using uppercase alpha digits.
      Parameters:
        `b` - the byte
      Returns:
        the 2-digit hex representation

    - #### byteToHex

          public static String byteToHex(byte b)

      Returns a two character string representation of the given byte, in hex.
      Parameters:
        `b` - the byte
      Returns:
        the string

    - #### toHexString

          public static String toHexString(byte[] bytes)

      Returns a string representation of the byte array as a hex dump, with spaces inserted to help reading the string.
      Parameters:
        `bytes` - the byte array
      Returns:
        the string

    - #### toHexArrayString

          public static String toHexArrayString(byte[] bytes)

      Returns a string representation of a byte array. For example:

               "0x[ 00 2e ff b7 ]"

      Parameters:
        `bytes` - the byte array
      Returns:
        a string representation

    - #### hexWithPrefix

          public static String hexWithPrefix(byte[] bytes)

      Returns a string representation of a byte array with "0x" prefix. For example:

               "0x002effb7"

      Parameters:
        `bytes` - the byte array
      Returns:
        a string representation

    - #### parseHexWithPrefix

          public static byte[] parseHexWithPrefix(String s)

      Helper method to convert the hex string with "0x" prefix to an array of bytes.
      Parameters:
        `s` - string with "0x" prefix
      Returns:
        byte[] the byte array

    - #### parseHex

          public static byte[] parseHex(String asciiHex)

      Generates a byte array by parsing the given ascii string of hex characters. This method is not a precise inverse of the `hex(byte[])` method, since it will happily deal with whitespace etc. between hex digits.

      This method ignores any non-word characters (including new-lines).

      Parameters:
        `asciiHex` - a string of ascii hex digits; must be an even length
      Returns:
        a byte array containing the byte representation of each two-byte ascii sequence
      Throws:
        `IllegalArgumentException` - if the string cannot be parsed as hex

    - #### getPadded64BitBytes

          public static byte[] getPadded64BitBytes(byte[] b)

      Examines the given byte array and returns an array that is padded out to a 64 bit boundary. That is, the returned array will have a length that is a multiple of 8 bytes.
      Parameters:
        `b` - the byte array
      Returns:
        a new array of bytes padded to a 64 bit boundary, or the original array if it is already padded (i.e. the length is a multiple of 8 bytes)

    - #### getRawBytes

          public static byte[] getRawBytes(String s)

      Helper method to convert the string to an array of bytes (without local replacement).
      Parameters:
        `s` - string to convert
      Returns:
        byte array of the string characters

    - #### getStringFromRawBytes

          public static String getStringFromRawBytes(byte[] bytes)

      Interprets the given array of bytes as a UTF-8 encoded string, and returns that string.
      Parameters:
        `bytes` - array of the string characters
      Returns:
        the string

    - #### getNullTerminatedAscii

          public static String getNullTerminatedAscii(byte[] bytes)

      Interprets the given array of bytes as a null-terminated ASCII string, and returns that string.
      Parameters:
        `bytes` - the null-terminated ASCII string encoded as bytes
      Returns:
        the string

    - #### getDebugString

          public static String getDebugString(String msg,
                              byte[] b,
                              int len)

      Creates a string of a byte array suitable for logging.
      Parameters:
        `msg` - a header message to display
        `b` - an array of bytes
        `len` - number of bytes in array
      Returns:
        log string

    - #### getDebugString

          public static String getDebugString(String msg,
                              byte[] b)

      Helper method to create log string of a byte array.
      Parameters:
        `msg` - header message to display
        `b` - an array of bytes
      Returns:
        log string

    - #### getByteArrayString

          public static String getByteArrayString(byte[] b)

      Returns a string representation of the given byte array.
      Parameters:
        `b` - an array of bytes
      Returns:
        a string representation of the byte array

    - #### getByteArrayString

          public static String getByteArrayString(byte[] b,
                                  int len)

      Returns a string representation of the given byte array.
      Parameters:
        `b` - an array of bytes
        `len` - the number of bytes in array
      Returns:
        a string representation of the byte array

    - #### getFilteredString

          public static String getFilteredString(byte[] b)

      Returns a 'filtered' string representation of the given byte array:

           "[<chars>] [<bytes>]"

      where all control chars in <chars> are replaced by '.' and <bytes> is of the form "00 ab ..".
      Parameters:
        `b` - byte array
      Returns:
        the filtered string representation

    - #### slurpBytesFromHexFile

          public static byte[] slurpBytesFromHexFile(String path,
                                     ClassLoader cl)
                                              throws IOException

      Reads in a human readable file of hex data and returns it as a byte array. If the resource file cannot be found, null is returned.

      For example, given the file contents:

               # comment
               ff ab 00
               # another comment
               11 22 33

      invoking the method will return the following byte array:

               [ 0xff, 0xab, 0x00, 0x11, 0x22, 0x33 ]

      Parameters:
        `path` - the path of the file resource
        `cl` - the classloader to use to locate the file resource
      Returns:
        a byte array equivalent to the hex data from the file
      Throws:
        `IOException` - if there is a problem reading the file
      See Also:
        `slurpBytesFromHexFile(Class, String)`

    - #### slurpBytesFromHexFile

          public static byte[] slurpBytesFromHexFile(Class<?> c,
                                     String baseName)
                                              throws IOException

      Reads in a human readable file of hex data and returns it as a byte array.

      This form locates the .hex file by looking in the same package as the given class, and using the given base name. Note that both the class and the .hex file need to be in the same jar file.

      For example, supposing the jar file contains:

           com/h3c/sdn/app/example/SomeObject.class
           com/h3c/sdn/app/example/MyPacketData.hex

      Then, to correctly load the hex file data, call:

           byte[] pktData =
               ByteUtils.slurpBytesFromHexFile(SomeObject.class, "MyPacketData");

      Parameters:
        `c` - the class used to locate the hex file
        `baseName` - the hex file base name
      Returns:
        a byte array equivalent to the hex data from the file
      Throws:
        `IOException` - if there is a problem reading the file
      See Also:
        `slurpBytesFromHexFile(String, ClassLoader)`

Copyright © 2014. All Rights Reserved.