public static void dump(byte[] data,
long offset,
OutputStream stream,
int index) throws IllegalArgumentException, IOException, ArrayIndexOutOfBoundsException {
if ((index < 0) || (index >= data.length))
{
throw new ArrayIndexOutOfBoundsException(
"illegal index: " + index + " into array of length "
+ data.length);
}
if (stream == null)
{
throw new IllegalArgumentException("cannot write to nullstream");
}
long display_offset = offset + index;
StringBuffer buffer = new StringBuffer(74);
for (int j = index; j < data.length; j += 16)
{
int chars_read = data.length - j;
if (chars_read > 16)
{
chars_read = 16;
}
buffer.append(dump(display_offset)).append(' ");
for (int k = 0; k < 16; k++)
{
if (k < chars_read)
{
buffer.append(dump(data[ k + j ]));
}
else
{
buffer.append(" ");
}
buffer.append(' ");
}
for (int k = 0; k < chars_read; k++)
{
if ((data[ k + j ] >= ' ") && (data[ k + j ] < 127))
{
buffer.append(( char ) data[ k + j ]);
}
else
{
buffer.append('.");
}
}
buffer.append(EOL);
stream.write(buffer.toString().getBytes());
stream.flush();
buffer.setLength(0);
display_offset += chars_read;
}
}
dump an array of bytes to an OutputStream |