Here you can find the source of toString(ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | the buffer to convert |
public static String toString(ByteBuffer buffer)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; public class Main { /**/*from w ww . ja v a2s . c om*/ * Convert the ByteBuffer to a UTF-8 String. * * @param buffer the buffer to convert * @return the String form of the buffer */ public static String toString(ByteBuffer buffer) { if (buffer == null) return null; byte[] array = buffer.hasArray() ? buffer.array() : null; if (array == null) { byte[] to = new byte[buffer.remaining()]; buffer.slice().get(to); return new String(to, 0, to.length, StandardCharsets.UTF_8); } return new String(array, buffer.arrayOffset() + buffer.position(), buffer.remaining(), StandardCharsets.UTF_8); } }