List of usage examples for io.netty.util CharsetUtil decoder
public static CharsetDecoder decoder(Charset charset)
From source file:io.gatling.netty.util.ahc.ByteBufUtils.java
License:Apache License
private static CharBuffer decode(ByteBuf src, Charset charset) { int readerIndex = src.readerIndex(); int len = src.readableBytes(); final CharsetDecoder decoder = CharsetUtil.decoder(charset); CharBuffer dst = pooledCharBuffer(len, decoder); if (src.nioBufferCount() == 1) { // Use internalNioBuffer(...) to reduce object creation. // BEWARE: NOT THREAD-SAFE decode(decoder, src.internalNioBuffer(readerIndex, len), dst); } else {/*ww w . j a v a2 s .c o m*/ // We use a heap buffer as CharsetDecoder is most likely able to use a fast-path if src and dst buffers // are both backed by a byte array. ByteBuf buffer = src.alloc().heapBuffer(len); try { buffer.writeBytes(src, readerIndex, len); // Use internalNioBuffer(...) to reduce object creation. decode(decoder, buffer.internalNioBuffer(buffer.readerIndex(), len), dst); } finally { // Release the temporary buffer again. buffer.release(); } } dst.flip(); return dst; }