Example usage for io.netty.util CharsetUtil getDecoder

List of usage examples for io.netty.util CharsetUtil getDecoder

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil getDecoder.

Prototype

@Deprecated
public static CharsetDecoder getDecoder(Charset charset) 

Source Link

Usage

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();
}