Here you can find the source of toString(ByteBuffer buffer, Charset charset)
Parameter | Description |
---|---|
buffer | The buffer to convert to a string. |
charset | The charset to use when converting bytes to characters. |
public static String toString(ByteBuffer buffer, Charset charset)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { /**/*from ww w. j a va2 s . c o m*/ * @param buffer The buffer to convert to a string. * @param charset The charset to use when converting bytes to characters. * @return A string representation of buffer's content. */ public static String toString(ByteBuffer buffer, Charset charset) { buffer = buffer.slice(); byte[] buf = new byte[buffer.remaining()]; buffer.get(buf); return new String(buf, charset); } public static String toString(CharBuffer buffer) { buffer = buffer.slice(); char[] buf = new char[buffer.remaining()]; buffer.get(buf); return new String(buf); } }