Here you can find the source of toString(final ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | The buffer to create a string from. |
public static String toString(final ByteBuffer buffer)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.util.Collection; import java.util.Iterator; public class Main { /**/*w w w. ja va 2s .c o m*/ * Returns the buffer as a string while preserving the buffer position and * limit. * * @param buffer * The buffer to create a string from. * @return The buffer string. */ public static String toString(final ByteBuffer buffer) { final int position = buffer.position(); final int limit = buffer.limit(); final byte[] data = new byte[buffer.remaining()]; buffer.get(data); final String dataString = new String(data); buffer.position(position); buffer.limit(limit); return dataString; } public static int remaining(final Collection<ByteBuffer> buffers) { int remaining = 0; for (final Iterator iter = buffers.iterator(); iter.hasNext();) { final ByteBuffer buf = (ByteBuffer) iter.next(); remaining += buf.remaining(); } return remaining; } }