diff options
author | Sven Gothel <[email protected]> | 2012-10-10 15:04:36 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-10-10 15:04:36 +0200 |
commit | fd8402ce90041aa506fdaddeedf7bbe09c56d788 (patch) | |
tree | 8abab8f21192243b89c7cd96119534750e191111 /src/java/com/jogamp/common/nio | |
parent | 8b755e327112fc1184e6dcdd20294a678f6d8f40 (diff) |
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.
Diffstat (limited to 'src/java/com/jogamp/common/nio')
-rwxr-xr-x | src/java/com/jogamp/common/nio/Buffers.java | 64 |
1 files changed, 63 insertions, 1 deletions
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<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof FloatBuffer) { + final FloatBuffer b = (FloatBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof IntBuffer) { + final IntBuffer b = (IntBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof ShortBuffer) { + final ShortBuffer b = (ShortBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof DoubleBuffer) { + final DoubleBuffer b = (DoubleBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof LongBuffer) { + final LongBuffer b = (LongBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } else if (buffer instanceof CharBuffer) { + final CharBuffer b = (CharBuffer)buffer; + for(int i=0; i<b.limit(); i++) { + if(0<i) { sb.append(", "); } + sb.append(b.get(i)); + } + } + sb.append("]"); + return sb; + } + } |