List of usage examples for io.netty.buffer UnpooledByteBufAllocator UnpooledByteBufAllocator
public UnpooledByteBufAllocator(boolean preferDirect)
From source file:org.wso2.carbon.gateway.internal.mediation.camel.CarbonMessageTypeConverter.java
License:Open Source License
private CompositeByteBuf aggregateChunks(Pipe pipe) { ByteBufInputStream byteBufInputStream = null; //Create an instance of composite byte buffer to hold the content chunks CompositeByteBuf content = new UnpooledByteBufAllocator(true).compositeBuffer(); try {/*from w w w .j ava2s . c om*/ //Check whether the pipe is filled with HTTP content chunks up to last chunk while (pipe.isEmpty() || !pipe.isLastChunkAdded()) { Thread.sleep(10); } //Get a clone of content chunk queue from the pipe BlockingQueue<ContentChunk> clonedContent = pipe.getClonedContentQueue(); //Traverse through the http content chunks and create the composite buffer while (true) { if (!clonedContent.isEmpty()) { //Retrieve the HTTP content chunk from cloned queue HttpContent chunk = ((HTTPContentChunk) clonedContent.take()).getHttpContent(); // Append the content of the chunk to the composite buffer if (chunk.content().isReadable()) { chunk.retain(); content.addComponent(chunk.content()); content.writerIndex(content.writerIndex() + chunk.content().readableBytes()); } } else { //When all the content chunks are read, break from the loop break; } } } catch (Exception e) { log.error("Error occurred during conversion from CarbonMessage", e); } //Return the composite buffer return content; }