List of usage examples for io.netty.buffer CompositeByteBuf readerIndex
@Override public int readerIndex()
From source file:org.wso2.carbon.gateway.internal.mediation.camel.CarbonMessageTypeConverter.java
License:Open Source License
@SuppressWarnings("unchecked") public <T> T convertTo(Class<T> type, Exchange exchange, Object value) { if (value instanceof CarbonMessage) { //Retrieving the Pipe from the carbon message Pipe pipe = ((CarbonMessage) value).getPipe(); //Input stream used for building the desired message ByteBufInputStream byteBufInputStream = null; //Create a composite buffer from content chunks in the pipe CompositeByteBuf contentBuf = aggregateChunks(pipe); //Check whether we have any content to be processed if (contentBuf.capacity() != 0) { try { if (type.isAssignableFrom(Document.class)) { //Convert the input stream into xml dom element return (T) toDocument(contentBuf, exchange); } else if (type.isAssignableFrom(DOMSource.class)) { return (T) toDOMSource(contentBuf, exchange); } else if (type.isAssignableFrom(SAXSource.class)) { return (T) toSAXSource(contentBuf, exchange); } else if (type.isAssignableFrom(StAXSource.class)) { return (T) toStAXSource(contentBuf, exchange); } else if (type.isAssignableFrom(StreamSource.class)) { return (T) toStreamSource(contentBuf, exchange); } else if (type.isAssignableFrom(InputStream.class)) { return (T) toInputStream(contentBuf, exchange); } else if (type.isAssignableFrom(String.class)) { return (T) toString(contentBuf, exchange); }//from w w w . ja va 2s .c o m } catch (UnsupportedEncodingException e) { log.error("Error occurred during type conversion", e); } finally { //Release the buffer if all the content has been consumed if (contentBuf.readerIndex() == contentBuf.writerIndex()) { contentBuf.release(); } } } } return null; }