Code with Finding: |
class Hex {
public static String bytesToASCIIString(byte[] data) {
String result = "";
for (int i = 0; i < data.length; i++) {
char c = (char)data[i];
result += Character.toString(PRINTABLE.indexOf(c) >= 0 ? c : '.');
}
return result;
}
}
class Hex {
/**
* Splits the byte array <code>src</code> into a number of byte arrays of
* length <code>width</code>. (Plus one of length less than width if
* <code>width</code> does not divide the length of <code>src</code>.)
*
* @param src the byte array to split.
* @param width a positive number.
*/
public static byte[][] split(byte[] src, int width) {
int rows = src.length / width;
int rest = src.length % width;
byte[][] dest = new byte[rows + (rest > 0 ? 1 : 0)][];
int k = 0;
for (int j = 0; j < rows; j++) {
dest[j] = new byte[width];
System.arraycopy(src,k,dest[j],0,width);
k += width;
}
if (rest > 0) {
dest[rows] = new byte[rest];
System.arraycopy(src,k,dest[rows],0,rest);
}
return dest;
}
}
|