Here you can find the source of readString(final ByteBuffer buffer, final String encoding)
Parameter | Description |
---|---|
buffer | The buffer to translate |
encoding | The encoding to use in translating bytes to characters |
public static String readString(final ByteBuffer buffer, final String encoding) throws UnsupportedEncodingException
//package com.java2s; //License from project: Apache License import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { /**/*from w ww . j a va 2 s . com*/ * Translate the given buffer into a string * * @param buffer The buffer to translate * @param encoding The encoding to use in translating bytes to characters */ public static String readString(final ByteBuffer buffer, final String encoding) throws UnsupportedEncodingException { byte[] bytes = new byte[buffer.remaining()]; buffer.get(bytes); return new String(bytes, encoding); } public static String readString(final ByteBuffer buffer) throws UnsupportedEncodingException { return readString(buffer, Charset.defaultCharset().toString()); } }