From fd8402ce90041aa506fdaddeedf7bbe09c56d788 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 10 Oct 2012 15:04:36 +0200 Subject: Buffers: Add convenient "public static StringBuilder toString(StringBuilder sb, Buffer buffer)" Sometimes we need to see details of a Buffer w/ it's content, e.g. for debugging purposes. --- src/java/com/jogamp/common/nio/Buffers.java | 64 ++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/src/java/com/jogamp/common/nio/Buffers.java b/src/java/com/jogamp/common/nio/Buffers.java index 63f3188..e4e20ef 100755 --- a/src/java/com/jogamp/common/nio/Buffers.java +++ b/src/java/com/jogamp/common/nio/Buffers.java @@ -858,7 +858,7 @@ public class Buffers { bytesRemaining = elementsRemaining * SIZEOF_INT; } else if (buffer instanceof ShortBuffer) { bytesRemaining = elementsRemaining * SIZEOF_SHORT; - }else if (buffer instanceof DoubleBuffer) { + } else if (buffer instanceof DoubleBuffer) { bytesRemaining = elementsRemaining * SIZEOF_DOUBLE; } else if (buffer instanceof LongBuffer) { bytesRemaining = elementsRemaining * SIZEOF_LONG; @@ -874,4 +874,66 @@ public class Buffers { } } + /** + * Appends Buffer details inclusive data to a StringBuilder instance. + * @param sb optional pass through StringBuilder + * @param buffer Any valid Buffer instance + * @return the modified StringBuilder containing the Buffer details + */ + public static StringBuilder toString(StringBuilder sb, Buffer buffer) { + if(null == sb) { + sb = new StringBuilder(); + } + sb.append(buffer.getClass().getSimpleName()); + sb.append("[pos ").append(buffer.position()).append(", lim ").append(buffer.limit()).append(", cap ").append(buffer.capacity()); + sb.append(", remaining ").append(buffer.remaining()); + sb.append("; array ").append(buffer.hasArray()).append(", direct ").append(buffer.isDirect()); + sb.append(", r/w ").append(!buffer.isReadOnly()).append(": "); + if (buffer instanceof ByteBuffer) { + final ByteBuffer b = (ByteBuffer)buffer; + for(int i=0; i