The list of methods to do ByteBuffer Print are organized into topic(s).
void
print(ByteBuffer bb) print
System.out.println("position =" + bb.position() + ", rmaining=" + bb.remaining() + ", limit=" + bb.limit());
void
printBuffer(ByteBuffer buffer) print Buffer
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
System.out.println(Arrays.toString(bytes));
void
printBuffer(ByteBuffer buffer) Prints the given buffer in hex format from the 0 position to the limit.
for (int i = 0; i < buffer.limit(); i++) {
System.out.format("%x ", buffer.get(i));
String
printBuffer(String msg, ByteBuffer buffer) Print the contents of the buffer out to the PrintStream in hex and ASCII.
StringBuffer sbuf = new StringBuffer();
int length = buffer.position();
sbuf.append("--------------------------------------------------------\n\n");
sbuf.append(msg).append("\n");
sbuf.append("\n");
sbuf.append("Thread : ").append(Thread.currentThread().getName()).append("\n");
sbuf.append("Total length (ByteBuffer position) : ").append(length).append("\n");
sbuf.append("Byte Buffer capacity : ").append(buffer.capacity()).append("\n\n");
...
String
printByteBuffer(ByteBuffer buf) print Byte Buffer
StringWriter w = new StringWriter();
byte[] data = bbToArray(buf);
w.append('[');
w.append(formatHex(data));
if (data.length == 4) {
w.append(" int:");
w.append(Integer.toString(buf.duplicate().getInt()));
} else if (data.length == 8) {
...
String
printData(ByteBuffer buffer, int len) print Data
StringBuilder result = new StringBuilder();
int counter = 0;
int length = buffer.remaining();
for (int i = 0; i < len; i++) {
counter++;
if (counter == 16) {
int charpoint = i - 15;
for (int a = 0; a < 16; a++) {
...
void
printImageContentsSubset(ByteBuffer buf, int w, int h) Print a small subset of the given image, namely the upper left 20x20.
int lineSize = w * 4;
w = (w > 20) ? 20 : w;
h = (h > 20) ? 20 : h;
IntBuffer ibuf = buf.asIntBuffer();
int nextLine = 0;
for (int y = 0; y < h; y++, nextLine += lineSize) {
ibuf.position(nextLine);
for (int x = 0; x < w; x++) {
...
void
println(String string, ByteBuffer buffer) println
if (buffer == null || !buffer.hasRemaining())
return;
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
buffer.flip();
println(string, bytes);