Here you can find the source of decodeNIO(String encoding, ByteBuffer bbuf)
private static String decodeNIO(String encoding, ByteBuffer bbuf)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetDecoder; import java.nio.charset.CodingErrorAction; public class Main { private static String decodeNIO(String encoding, ByteBuffer bbuf) { Charset cset = Charset.forName(encoding); CharsetDecoder csetdecoder = cset.newDecoder(); csetdecoder.onMalformedInput(CodingErrorAction.REPLACE); csetdecoder.onUnmappableCharacter(CodingErrorAction.REPLACE); try {/*from w w w . j ava2s.c o m*/ CharBuffer cbuf = csetdecoder.decode(bbuf); return cbuf.toString(); } catch (CharacterCodingException e) { e.printStackTrace(); } return null; } }