Java Utililty Methods ByteBuffer Dump

List of utility methods to do ByteBuffer Dump

Description

The list of methods to do ByteBuffer Dump are organized into topic(s).

Method

StringdumpBytes(ByteBuffer byteBuffer)
Convert the byteBuffer into a String to be used for logging and debugging.
byteBuffer.mark();
int length = byteBuffer.limit() - byteBuffer.position();
byte[] dst = new byte[length];
byteBuffer.get(dst);
byteBuffer.reset();
return dumpBytes(dst);
voiddumpBytes(PrintStream ps, ByteBuffer buf)
Dup dat into binary format like 00010203 04050607 08090001 02030405 06070809 00010203 04050607 08090001 08090001 02030405 06070809 00010203 04050607 08090001 02030405 06070809 06070809 00010203 04050607 08090001 02030405 ...
dumpBytes(ps, buf.array());
StringdumpHexString(ByteBuffer bb)
dump Hex String
byte[] data = new byte[bb.remaining()];
int position = bb.position();
bb.get(data);
bb.position(position);
return dumpHexString(data);
voiddumpNextNBytes(ByteBuffer buffer, int n)
dump Next N Bytes
if (!debugging())
    return;
int oldPosition = buffer.position();
byte[] bytesToRead = new byte[Math.min(buffer.remaining(), n)];
buffer.get(bytesToRead);
log(Integer.toHexString(oldPosition) + "  " + getHexString(bytesToRead));
buffer.position(oldPosition);
voiddumpToFile(ByteBuffer buf, String fileName)
Dump the given ByteBuffer 's bytes to a file.
try {
    final FileOutputStream fos = new FileOutputStream(fileName);
    fos.write(buf.array());
    fos.close();
} catch (Exception e) {
    e.printStackTrace();
    System.exit(-1);
voidhexDump(ByteBuffer buffer)

Write a hexidecimal dump, with byte offsets and character conversions in the style of hexdump -C, to the standard output stream.

if (buffer == null)
    throw new NullPointerException("Cannot create a hex dump of a null buffer.");
int positionCache = buffer.position();
buffer.rewind();
int count = 0;
while (buffer.hasRemaining()) {
    StringBuffer nextLine = new StringBuffer(80);
    byte[] lineBytes = new byte[buffer.remaining() > 16 ? 16 : buffer.remaining()];
...
voidhexDump(PrintStream ps, ByteBuffer bb)
Prints a hex dump of the specified ByteBuffer to the specified PrintStream .
int inLine = 0;
for (int pos = 0; pos < bb.remaining(); pos++) {
    final int b = bb.get(bb.position() + pos) & 0xff;
    if (inLine == 0)
        ps.print(hexOffset(pos, 6));
    ps.print(Character.forDigit(b / 16, 16));
    ps.print(Character.forDigit(b % 16, 16));
    ps.print(" ");
...
voidprintByteDump(StringBuilder strBuilder, ByteBuffer data, int offset, int length, int columnNum)
print Byte Dump
int currentPosition = data.position();
int columnCount = 0;
final int endIndex = offset + length;
for (int i = offset; i < endIndex; i++) {
    if (columnCount == columnNum) {
        strBuilder.append('\n');
        columnCount = 0;
    strBuilder.append(String.format("%02x ", data.get(i)));
    columnCount++;
strBuilder.append('\n');
data.position(currentPosition);
voidsetDecreasedBuffer(ByteBuffer memoryDumpReader, long baseAddressValue, int innerPointerOffset, long memoryDumpStartingOffset)
set Decreased Buffer
int decreasedBufferPosition = (int) (baseAddressValue - memoryDumpStartingOffset + innerPointerOffset);
if (decreasedBufferPosition < 0) {
    decreasedBufferPosition = 0;
memoryDumpReader.position(decreasedBufferPosition);
StringBuildertoHexDumpString(ByteBuffer data)
Generates a string hex dump from a ByteBuffer
StringBuilder sb = new StringBuilder();
for (int i = 0; i < data.position(); i++) {
    byte c = data.get(i);
    if (i > 0)
        sb.append(' ');
    sb.append(toHexDumpString(c));
return sb;
...