List of utility methods to do ByteBuffer to String
String | toString(ByteBuffer bytes) Extract the byte[] within the given ByteBuffer and decode into a String using UTF-8. return toString(copyBytes(bytes));
|
String | toString(ByteBuffer sequence) Convert a byte buffer to a string in platform default encoding. return new String(sequence.array(), sequence.position(), sequence.remaining()); |
String | toString(ByteBuffer value, String charsetName) convert a ByteBuffer to a String ByteBuffer is reset to its original state. String result = null; try { result = new String(toBytes(value), charsetName); } catch (Exception e) { return result; |
String | toString(final ByteBuffer buffer) Returns the buffer as a string while preserving the buffer position and limit. 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; ... |
String | toString(final ByteBuffer buffer) Convert ByteBuffer to string, assuming UTF-8 encoding in the buffer. byte[] array = new byte[buffer.remaining()]; buffer.get(array); return new String(array, Charset.forName("UTF-8")); |
String | toString(final ByteBuffer buffer) Converts a byte buffer into a string in the UTF-8 character set. return toCharBuffer(buffer).toString();
|
String | toStringBinary(ByteBuffer buf) Converts the given byte buffer, from its array offset to its limit, to a string. if (buf == null) return "null"; return toStringBinary(buf.array(), buf.arrayOffset(), buf.limit()); |
String | toStringBinary(ByteBuffer buf) Converts the given byte buffer, from its array offset to its limit, to a string. if (buf == null) return "null"; return toStringBinary(buf.array(), buf.arrayOffset(), buf.limit()); |
void | toText(ByteBuffer data, StringBuilder result, int cnt) Gets last cnt read bytes from the data buffer and puts into result buffer in special format:
int charPos = data.position() - cnt; for (int a = 0; a < cnt; a++) { int c = data.get(charPos++); if (c > 0x1f && c < 0x80) result.append((char) c); else result.append('.'); |
String | toTextAll(ByteBuffer bytes) Convert whole byte buffer to UTF-8 String. return new String(bytes.array(), UTF8); |