Java Utililty Methods ByteBuffer Print

List of utility methods to do ByteBuffer Print

Description

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

Method

voidprint(ByteBuffer bb)
print
System.out.println("position =" + bb.position() + ", rmaining=" + bb.remaining() + ", limit=" + bb.limit());
Stringprint(ByteBuffer byteBuffer)
print
String text = new String(byteBuffer.array());
return print(text);
voidprintBuffer(ByteBuffer buffer)
print Buffer
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
System.out.println(Arrays.toString(bytes));
voidprintBuffer(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));
StringprintBuffer(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");
...
StringprintByteBuffer(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) {
...
StringprintData(ByteBuffer buf, int offset, int len)
print Data
byte[] tmp = new byte[len];
int pos = buf.position();
buf.position(offset);
buf.get(tmp);
buf.position(pos);
return printData(tmp, len);
StringprintData(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++) {
...
voidprintImageContentsSubset(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++) {
...
voidprintln(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);