Here you can find the source of newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length)
public static String newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharsetDecoder; import java.nio.charset.CoderResult; public class Main { public static String newStringFromSplit(CharsetDecoder decoder, CharsetDecoder utf8Decoder, String encoding, byte[] fieldBytes, int length) { ByteBuffer fieldBuf = ByteBuffer.wrap(fieldBytes, 0, length); CharBuffer fieldCharBuf = CharBuffer.allocate(length); utf8Decoder.reset();//w w w.j av a2 s .c om CoderResult res = utf8Decoder.decode(fieldBuf, fieldCharBuf, true); if (res.isError() && decoder != null) { decoder.reset(); res = decoder.decode(fieldBuf, fieldCharBuf, true); if (!res.isError()) { decoder.flush(fieldCharBuf); return new String(fieldCharBuf.array()); } } else { utf8Decoder.flush(fieldCharBuf); return new String(fieldCharBuf.array()); } return ""; } }