Code with Finding: |
class Hex {
/**
* Hexadecimal representation of <code>data</code> with spaces between
* individual bytes.
*
* @param data the byte array to print.
*
* @return spaced hexadecimal representation of <code>data</code>.
*/
public static String bytesToSpacedHexString(byte[] data) {
String result = "";
for (int i = 0; i < data.length; i++) {
result += byteToHexString(data[i]);
result += (i < data.length - 1) ? " " : "";
}
result = result.toUpperCase();
return result;
}
}
class Hex {
/**
* Hexadecimal representations of <code>data</code> with spaces between
* individual bytes. Each string represents <code>columns</code> bytes,
* except for the last one, which represents at most <code>columns</code>
* bytes.
*
* @param data the byte array to represent.
* @param columns the width of each line.
* @param padWidth resulting strings will be padded to this length with
* spaces to the right.
*
* @return spaced hexadecimal representations of <code>data</code>.
*/
private static String[] bytesToSpacedHexStrings(byte[] data, int columns,
int padWidth) {
byte[][] src = split(data,columns);
String[] result = new String[src.length];
for (int j = 0; j < src.length; j++) {
result[j] = bytesToSpacedHexString(src[j]);
result[j] = pad(result[j],padWidth,' ',RIGHT);
}
return result;
}
}
|