Class HexDump
Various static methods helpful for dumping decimal and hexadecimal values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
byteArrayToHexString
(byte[] b) Create a continuous hex string representation of a byte array.static String
byteArrayToHexString
(byte[] b, int offset, int length) Create a continuous hex string representation of a specified portion of a byte array.static String
byteArrayToPrintableString
(byte[] b) Create a printable string representation of a specified portion of a byte array in the default character set.static 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 String
byteToPaddedDecimalString
(int i) Convert an unsigned byte value to a decimal string of three characters with leading space padding.static String
byteToPaddedHexString
(int i) Convert an unsigned byte value to a hexadecimal string of two characters with leading zero padding.static String
byteToPaddedHexStringWith0x
(int i) Convert an unsigned byte value to a hexadecimal string of two characters with leading 0x and leading zero padding.static String
dump
(byte[] b) Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.static String
dump
(byte[] b, int lng) Create a dump of the decimal offset, hexadecimal values and printable string values of a byte array.static 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 String
Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.static String
Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.static String
Create a dump of the decimal offset, hexadecimal values of the Unicode code points and printable string values of a String.static String
intToPaddedDecimalString
(int i) Convert an integer value to a decimal string of nine characters with leading space padding.static String
intToPaddedHexString
(int i) Convert an integer value to a hexadecimal string of eight characters with leading zero padding.static 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
Unit test.static String
shortToPaddedDecimalString
(int i) Convert an unsigned short value to a decimal string of six characters with leading space padding.static String
shortToPaddedHexString
(int i) Convert an unsigned short value to a hexadecimal string of four characters with leading zero padding.static String
shortToPaddedHexStringWith0x
(int i) Convert an unsigned short value to a hexadecimal string of four characters with leading 0x and leading zero padding.static String
toPaddedDecimalString
(int i, char pad, int length, String prefix, 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 String
toPaddedHexString
(int i, char pad, int length, String prefix, String suffix) Convert an integer value to a hexadecimal string, padding it to a specified length, and prepending a prefix and appending a suffix.
-
Method Details
-
toPaddedDecimalString
public static String toPaddedDecimalString(int i, char pad, int length, String prefix, 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 dumppad
- the pad character to append before the string value of the integer if necessarylength
- the desired length of string converted integer and padding (not including the prefix or suffix)prefix
- the string to prependsuffix
- the string to append- Returns:
- the prefix, padded decimal string and suffix
-
byteToPaddedDecimalString
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
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
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
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 dumppad
- the pad character to append before the string value of the integer if necessarylength
- the desired length of string converted integer and padding (not including the prefix or suffix)prefix
- the string to prependsuffix
- the string to append- Returns:
- the prefix, padded hexadecimal string and suffix
-
byteToPaddedHexString
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
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
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
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
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
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
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 arrayoffset
- the start of the bytes to be extractedlength
- the number of bytes to be extracted- Returns:
- a string of the specified length containing the printable characters of the supplied bytes
-
byteArrayToPrintableString
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
Create a continuous hex string representation of a specified portion of a byte array.
- Parameters:
b
- the byte arrayoffset
- the start of the bytes to be extractedlength
- the number of bytes to be extracted- Returns:
- a string containing the hex representation of the supplied bytes
-
byteArrayToHexString
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
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 dumpedoffset
- the offset into the buffer to be dumpedlng
- the number of bytes to be dumped- Returns:
- a string containing the multiline result
-
dump
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 dumpedlng
- the number of bytes to be dumped- Returns:
- a string containing the multiline result
-
dump
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
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 dumpedoffset
- the offset into the String to be dumpedlng
- the number of characters to be dumped- Returns:
- a string containing the multiline result
-
dump
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 dumpedlng
- the number of characters to be dumped- Returns:
- a string containing the multiline result
-
dump
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
Unit test.
- Parameters:
arg
- ignored
-