Example usage for io.netty.buffer CompositeByteBuf toString

List of usage examples for io.netty.buffer CompositeByteBuf toString

Introduction

In this page you can find the example usage for io.netty.buffer CompositeByteBuf toString.

Prototype

@Override
    public String toString(Charset charset) 

Source Link

Usage

From source file:org.asynchttpclient.netty.util.ByteBufUtils.java

License:Open Source License

public static String byteBuf2String(Charset charset, ByteBuf... bufs) throws CharacterCodingException {
    if (charset == UTF_8 || charset == US_ASCII) {
        return Utf8ByteBufCharsetDecoder.decodeUtf8(bufs);
    } else {/*from  ww w . jav a2 s  . c  om*/
        CompositeByteBuf composite = Unpooled.compositeBuffer(bufs.length);

        try {
            for (ByteBuf buf : bufs) {
                buf.retain();
                composite.addComponent(buf);
            }

            return composite.toString(charset);

        } finally {
            composite.release();
        }
    }
}