List of usage examples for io.netty.util CharsetUtil getDecoder
@Deprecated public static CharsetDecoder getDecoder(Charset charset)
From source file:net.tomp2p.storage.AlternativeCompositeByteBuf.java
License:Apache License
private static String decodeString(ByteBuffer src, Charset charset) { final CharsetDecoder decoder = CharsetUtil.getDecoder(charset); final CharBuffer dst = CharBuffer.allocate((int) ((double) src.remaining() * decoder.maxCharsPerByte())); try {//from ww w . java 2 s.c om CoderResult cr = decoder.decode(src, dst, true); if (!cr.isUnderflow()) { cr.throwException(); } cr = decoder.flush(dst); if (!cr.isUnderflow()) { cr.throwException(); } } catch (CharacterCodingException x) { throw new IllegalStateException(x); } return dst.flip().toString(); }