public class HexDump
extends java.lang.Object
Various static methods helpful for dumping decimal and hexadecimal values.
Modifier and Type | Method and 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.
|
public static java.lang.String byteArrayToHexString(byte[] b)
Create a continuous hex string representation of a byte array.
b
- the byte arraypublic 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.
b
- the byte arrayoffset
- the start of the bytes to be extractedlength
- the number of bytes to be extractedpublic 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.
b
- the byte arraypublic 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.
b
- the byte arrayoffset
- the start of the bytes to be extractedlength
- the number of bytes to be extractedpublic static java.lang.String byteToPaddedDecimalString(int i)
Convert an unsigned byte value to a decimal string of three characters with leading space padding.
i
- the unsigned byte valuepublic static java.lang.String byteToPaddedHexString(int i)
Convert an unsigned byte value to a hexadecimal string of two characters with leading zero padding.
i
- the unsigned byte valuepublic 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.
i
- the unsigned byte valuepublic 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.
b
- the byte array to be dumped in its entiretypublic 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.
b
- the byte array to be dumpedlng
- the number of bytes to be dumpedpublic 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.
b
- the byte array to be dumpedoffset
- the offset into the buffer to be dumpedlng
- the number of bytes to be dumpedpublic 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.
s
- the String to be dumped dumped in its entiretypublic 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.
s
- the String to be dumpedlng
- the number of characters to be dumpedpublic 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.
s
- the String to be dumpedoffset
- the offset into the String to be dumpedlng
- the number of characters to be dumpedpublic static java.lang.String intToPaddedDecimalString(int i)
Convert an integer value to a decimal string of nine characters with leading space padding.
i
- the integer valuepublic static java.lang.String intToPaddedHexString(int i)
Convert an integer value to a hexadecimal string of eight characters with leading zero padding.
i
- the integer valuepublic 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.
i
- the integer valuepublic static boolean isPrintableCharacter(char c)
Test whether or not a character in the default character set is printable.
c
- character to testpublic static void main(java.lang.String[] arg)
Unit test.
arg
- ignoredpublic static java.lang.String shortToPaddedDecimalString(int i)
Convert an unsigned short value to a decimal string of six characters with leading space padding.
i
- the unsigned short valuepublic static java.lang.String shortToPaddedHexString(int i)
Convert an unsigned short value to a hexadecimal string of four characters with leading zero padding.
i
- the unsigned short valuepublic 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.
i
- the unsigned short valuepublic 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.
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 appendpublic 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.
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