In Method: | bytesToPrettyString(byte[], int, boolean, int, String, boolean) |
Code with Finding: |
class Hex {
/**
* Gets a human readable hexadecimal representation of <code>data</code>
* with spaces and newlines in <code>columns</code> columns.
* Will print an index before each line if <code>useIndex</code> is
* <code>true</code>.
* Will print an ASCII representation after each line if
* <code>useASCII</code> is <code>true</code>.
*
* @param data the byte array to print.
* @param columns the number of bytes per line.
* @param useIndex a boolean indicating whether each line should be started
* with an index.
* @param indexPadWidth the padding width for index.
* @param altIndex string to prefix if no index is used.
* @param useASCII a boolean indicating whether each line should be ended
* with an ASCII representation of the bytes in that line.
*
* @return a hexadecimal representation of <code>data</code>.
*/
public static String bytesToPrettyString(byte[] data, int columns,
boolean useIndex, int indexPadWidth, String altIndex,
boolean useASCII) {
String result = "";
String[] hexStrings = bytesToSpacedHexStrings(data,columns,3 * columns);
String[] asciiStrings = bytesToASCIIStrings(data,columns,columns);
for (int j = 0; j < hexStrings.length; j++) {
if (useIndex) {
String prefix = Integer.toHexString(j * columns).toUpperCase();
result += pad(prefix,indexPadWidth,'0',LEFT) + ": ";
} else {
String prefix = j == 0 ? altIndex : "";
result += pad(prefix,indexPadWidth,' ',LEFT) + " ";
}
result += hexStrings[j];
if (useASCII) {
result += " " + asciiStrings[j];
}
result += "\n";
}
return result;
}
}
|