Class HexDump


  • public class HexDump
    extends java.lang.Object

    Various static methods helpful for dumping decimal and hexadecimal values.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String byteArrayToHexString​(byte[] b)
      Create a continuous hex string representation of a byte array.
      static java.lang.String byteArrayToHexString​(byte[] b, int offset, int length)
      Create a continuous hex string representation of a specified portion of a byte array.
      static java.lang.String byteArrayToPrintableString​(byte[] b)
      Create a printable string representation of a specified portion of a byte array in the default character set.
      static java.lang.String byteArrayToPrintableString​(byte[] b, int offset, int length)
      Create a printable string representation of a specified portion of a byte array in the default character set.
      static java.lang.String byteToPaddedDecimalString​(int i)
      Convert an unsigned byte value to a decimal string of three characters with leading space padding.
      static java.lang.String byteToPaddedHexString​(int i)
      Convert an unsigned byte value to a hexadecimal string of two characters with leading zero padding.
      static java.lang.String byteToPaddedHexStringWith0x​(int i)
      Convert an unsigned byte value to a hexadecimal string of two characters with leading 0x and leading zero padding.
      static java.lang.String dump​(byte[] b)
      Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.
      static java.lang.String dump​(byte[] b, int lng)
      Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.
      static java.lang.String dump​(byte[] b, int offset, int lng)
      Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.
      static java.lang.String dump​(java.lang.String s)
      Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.
      static java.lang.String dump​(java.lang.String s, int lng)
      Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.
      static java.lang.String dump​(java.lang.String s, int offset, int lng)
      Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.
      static java.lang.String intToPaddedDecimalString​(int i)
      Convert an integer value to a decimal string of nine characters with leading space padding.
      static java.lang.String intToPaddedHexString​(int i)
      Convert an integer value to a hexadecimal string of eight characters with leading zero padding.
      static java.lang.String intToPaddedHexStringWith0x​(int i)
      Convert an integer value to a hexadecimal string of eight characters with leading 0x and leading zero padding.
      static boolean isPrintableCharacter​(char c)
      Test whether or not a character in the default character set is printable.
      static void main​(java.lang.String[] arg)
      Unit test.
      static java.lang.String shortToPaddedDecimalString​(int i)
      Convert an unsigned short value to a decimal string of six characters with leading space padding.
      static java.lang.String shortToPaddedHexString​(int i)
      Convert an unsigned short value to a hexadecimal string of four characters with leading zero padding.
      static java.lang.String shortToPaddedHexStringWith0x​(int i)
      Convert an unsigned short value to a hexadecimal string of four characters with leading 0x and leading zero padding.
      static java.lang.String toPaddedDecimalString​(int i, char pad, int length, java.lang.String prefix, java.lang.String suffix)
      Convert an integer value to a decimal string, padding it to a specified length, and prepending a prefix and appending a suffix.
      static java.lang.String toPaddedHexString​(int i, char pad, int length, java.lang.String prefix, java.lang.String suffix)
      Convert an integer value to a hexadecimal string, padding it to a specified length, and prepending a prefix and appending a suffix.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toPaddedDecimalString

        public static java.lang.String toPaddedDecimalString​(int i,
                                                             char pad,
                                                             int length,
                                                             java.lang.String prefix,
                                                             java.lang.String suffix)

        Convert an integer value to a decimal string, padding it to a specified length, and prepending a prefix and appending a suffix.

        Parameters:
        i - the integer to dump
        pad - the pad character to append before the string value of the integer if necessary
        length - the desired length of string converted integer and padding (not including the prefix or suffix)
        prefix - the string to prepend
        suffix - the string to append
        Returns:
        the prefix, padded decimal string and suffix
      • byteToPaddedDecimalString

        public static java.lang.String byteToPaddedDecimalString​(int i)

        Convert an unsigned byte value to a decimal string of three characters with leading space padding.

        Parameters:
        i - the unsigned byte value
        Returns:
        the padded decimal string
      • shortToPaddedDecimalString

        public static java.lang.String shortToPaddedDecimalString​(int i)

        Convert an unsigned short value to a decimal string of six characters with leading space padding.

        Parameters:
        i - the unsigned short value
        Returns:
        the padded decimal string
      • intToPaddedDecimalString

        public static java.lang.String intToPaddedDecimalString​(int i)

        Convert an integer value to a decimal string of nine characters with leading space padding.

        Parameters:
        i - the integer value
        Returns:
        the padded decimal string
      • toPaddedHexString

        public static java.lang.String toPaddedHexString​(int i,
                                                         char pad,
                                                         int length,
                                                         java.lang.String prefix,
                                                         java.lang.String suffix)

        Convert an integer value to a hexadecimal string, padding it to a specified length, and prepending a prefix and appending a suffix.

        Parameters:
        i - the integer to dump
        pad - the pad character to append before the string value of the integer if necessary
        length - the desired length of string converted integer and padding (not including the prefix or suffix)
        prefix - the string to prepend
        suffix - the string to append
        Returns:
        the prefix, padded hexadecimal string and suffix
      • byteToPaddedHexString

        public static java.lang.String byteToPaddedHexString​(int i)

        Convert an unsigned byte value to a hexadecimal string of two characters with leading zero padding.

        Parameters:
        i - the unsigned byte value
        Returns:
        the padded hexadecimal string
      • shortToPaddedHexString

        public static java.lang.String shortToPaddedHexString​(int i)

        Convert an unsigned short value to a hexadecimal string of four characters with leading zero padding.

        Parameters:
        i - the unsigned short value
        Returns:
        the padded decimal string
      • intToPaddedHexString

        public static java.lang.String intToPaddedHexString​(int i)

        Convert an integer value to a hexadecimal string of eight characters with leading zero padding.

        Parameters:
        i - the integer value
        Returns:
        the padded decimal string
      • byteToPaddedHexStringWith0x

        public static java.lang.String byteToPaddedHexStringWith0x​(int i)

        Convert an unsigned byte value to a hexadecimal string of two characters with leading 0x and leading zero padding.

        Parameters:
        i - the unsigned byte value
        Returns:
        the padded hexadecimal string
      • shortToPaddedHexStringWith0x

        public static java.lang.String shortToPaddedHexStringWith0x​(int i)

        Convert an unsigned short value to a hexadecimal string of four characters with leading 0x and leading zero padding.

        Parameters:
        i - the unsigned short value
        Returns:
        the padded decimal string
      • intToPaddedHexStringWith0x

        public static java.lang.String intToPaddedHexStringWith0x​(int i)

        Convert an integer value to a hexadecimal string of eight characters with leading 0x and leading zero padding.

        Parameters:
        i - the integer value
        Returns:
        the padded decimal string
      • isPrintableCharacter

        public static boolean isPrintableCharacter​(char c)

        Test whether or not a character in the default character set is printable.

        Parameters:
        c - character to test
        Returns:
        true if character is printable
      • byteArrayToPrintableString

        public static java.lang.String byteArrayToPrintableString​(byte[] b,
                                                                  int offset,
                                                                  int length)

        Create a printable string representation of a specified portion of a byte array in the default character set.

        Unprintable characters are represented by a period ('.') character.

        Parameters:
        b - the byte array
        offset - the start of the bytes to be extracted
        length - the number of bytes to be extracted
        Returns:
        a string of the specified length containing the printable characters of the supplied bytes
      • byteArrayToPrintableString

        public static java.lang.String byteArrayToPrintableString​(byte[] b)

        Create a printable string representation of a specified portion of a byte array in the default character set.

        Unprintable characters are represented by a period ('.') character.

        Parameters:
        b - the byte array
        Returns:
        a string containing the printable characters of the supplied bytes
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] b,
                                                            int offset,
                                                            int length)

        Create a continuous hex string representation of a specified portion of a byte array.

        Parameters:
        b - the byte array
        offset - the start of the bytes to be extracted
        length - the number of bytes to be extracted
        Returns:
        a string containing the hex representation of the supplied bytes
      • byteArrayToHexString

        public static java.lang.String byteArrayToHexString​(byte[] b)

        Create a continuous hex string representation of a byte array.

        Parameters:
        b - the byte array
        Returns:
        a string containing the hex representation of the supplied bytes
      • dump

        public static java.lang.String dump​(byte[] b,
                                            int offset,
                                            int lng)

        Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.

        The result is similar to a dump produced by the unix od or MacOS X 'hexdump -C' commands.

        Parameters:
        b - the byte array to be dumped
        offset - the offset into the buffer to be dumped
        lng - the number of bytes to be dumped
        Returns:
        a string containing the multiline result
      • dump

        public static java.lang.String dump​(byte[] b,
                                            int lng)

        Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.

        The result is similar to a dump produced by the unix od or MacOS X 'hexdump -C' commands.

        Parameters:
        b - the byte array to be dumped
        lng - the number of bytes to be dumped
        Returns:
        a string containing the multiline result
      • dump

        public static java.lang.String dump​(byte[] b)

        Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.

        The result is similar to a dump produced by the unix od or MacOS X 'hexdump -C' commands.

        Parameters:
        b - the byte array to be dumped in its entirety
        Returns:
        a string containing the multiline result
      • dump

        public static java.lang.String dump​(java.lang.String s,
                                            int offset,
                                            int lng)

        Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.

        Parameters:
        s - the String to be dumped
        offset - the offset into the String to be dumped
        lng - the number of characters to be dumped
        Returns:
        a string containing the multiline result
      • dump

        public static java.lang.String dump​(java.lang.String s,
                                            int lng)

        Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.

        Parameters:
        s - the String to be dumped
        lng - the number of characters to be dumped
        Returns:
        a string containing the multiline result
      • dump

        public static java.lang.String dump​(java.lang.String s)

        Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.

        Parameters:
        s - the String to be dumped dumped in its entirety
        Returns:
        a string containing the multiline result
      • main

        public static void main​(java.lang.String[] arg)

        Unit test.

        Parameters:
        arg - ignored