org.jboss.netty.buffer.ChannelBufferInputStream Java Examples

The following examples show how to use org.jboss.netty.buffer.ChannelBufferInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThriftFrameDecoder.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext ctx,
                        Channel channel,
                        ChannelBuffer buffer) throws Exception {
    List<SyncMessage> ms = null;
    ChannelBuffer frame = null;
    while (null != (frame = (ChannelBuffer) super.decode(ctx, channel, 
                                                         buffer))) {
        if (ms == null) ms = new ArrayList<SyncMessage>();
        ChannelBufferInputStream is = new ChannelBufferInputStream(frame);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(is));
        SyncMessage bsm = new SyncMessage();
        bsm.read(thriftProtocol);
        ms.add(bsm);
    }
    return ms;
}
 
Example #2
Source File: RpcResponseDecode.java    From voyage with Apache License 2.0 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext context, Channel channel,
		ChannelBuffer buffer) throws Exception {
	if (buffer.readableBytes() < 2) {
		return null;
	}
	byte byte1 = buffer.readByte();
	byte byte2 = buffer.readByte();
	if (byte1 != Constants.MAGIC_HIGH || byte2 != Constants.MAGIC_LOW) {
		throw new RuntimeException("magic number not right");
	}
	ChannelBufferInputStream in = new ChannelBufferInputStream(buffer);
	RpcResponse response = MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).decodeResponse(in);
	return response;
}
 
Example #3
Source File: RpcRequestDecode.java    From voyage with Apache License 2.0 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
		ChannelBuffer buffer) throws Exception {
	if (buffer.readableBytes() < 2) {
		return null;
	}
	byte byte1 = buffer.readByte();
	byte byte2 = buffer.readByte();
	if (byte1!=Constants.MAGIC_HIGH || byte2!=Constants.MAGIC_LOW) {
		throw new RuntimeException("magic number not right");
	}
	ChannelBufferInputStream in = new ChannelBufferInputStream(buffer);
	RpcRequest request = MySerializerFactory.getInstance(Constants.DEFAULT_RPC_CODE_MODE).decodeRequest(in);
	return request;
}
 
Example #4
Source File: NettyImapRequestLineReader.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Return a {@link ChannelBufferInputStream} if the wrapped
 * {@link ChannelBuffer} contains enough data. If not it will throw a
 * {@link NotEnoughDataException}
 */
@Override
public InputStream read(int size, boolean extraCRLF) throws DecodingException {
    int crlf = 0;
    if (extraCRLF) {
        crlf = 2;
    }
    
    if (maxLiteralSize > 0 && maxLiteralSize > size) {
        throw new DecodingException(HumanReadableText.FAILED, "Specified literal is greater then the allowed size");
    }
    // Check if we have enough data
    if (size + crlf > buffer.readableBytes()) {
        // ok let us throw a exception which till the decoder how many more
        // bytes we need
        throw new NotEnoughDataException(size + read + crlf);
    }

    // Unset the next char.
    nextSeen = false;
    nextChar = 0;

    // limit the size via commons-io as ChannelBufferInputStream size limiting is buggy
    InputStream in = new BoundedInputStream(new ChannelBufferInputStream(buffer), size); 
    if (extraCRLF) {
        return new EolInputStream(this, in);
    } else {
        return in;
    }
}
 
Example #5
Source File: PickleDecoder.java    From kairos-carbon with Apache License 2.0 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext channelHandlerContext,
		Channel channel, Object o) throws Exception
{
	ChannelBuffer cb = (ChannelBuffer)o;

	Unpickler unpickler = new Unpickler();

	return (unpickler.load(new ChannelBufferInputStream(cb)));
}
 
Example #6
Source File: OpUpdate.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
    super.decode( buffer );
    buffer.readInt();
    fullCollectionName = readCString( buffer );
    flags = buffer.readInt();
    selector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
    update = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
}
 
Example #7
Source File: OpQuery.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
    super.decode( buffer );
    flags = buffer.readInt();
    fullCollectionName = readCString( buffer );
    numberToSkip = buffer.readInt();
    numberToReturn = buffer.readInt();
    query = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
    if ( buffer.readable() ) {
        returnFieldSelector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
        logger.info( "found fieldSeclector: {}", returnFieldSelector );
    }
}
 
Example #8
Source File: OpReply.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
    super.decode( buffer );

    responseFlags = buffer.readInt();
    cursorID = buffer.readLong();
    startingFrom = buffer.readInt();
    numberReturned = buffer.readInt();

    while ( buffer.readable() ) {
        documents.add( BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ) );
    }
}
 
Example #9
Source File: OpInsert.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
    super.decode( buffer );

    flags = buffer.readInt();
    fullCollectionName = readCString( buffer );

    while ( buffer.readable() ) {
        documents.add( BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) ) );
    }
}
 
Example #10
Source File: OpDelete.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public void decode( ChannelBuffer buffer ) throws IOException {
    super.decode( buffer );
    buffer.readInt();
    fullCollectionName = readCString( buffer );
    flags = buffer.readInt();
    selector = BSONUtils.decoder().readObject( new ChannelBufferInputStream( buffer ) );
}
 
Example #11
Source File: NettyHandlerContainer.java    From recipes-rss with Apache License 2.0 5 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext context, MessageEvent e) throws Exception {
	HttpRequest request = (HttpRequest) e.getMessage();
	String base = getBaseUri(request);
	URI baseUri = new URI(base);
	URI requestUri = new URI(base.substring(0, base.length() - 1) + request.getUri());
	ContainerRequest cRequest = new ContainerRequest(application, request
			.getMethod().getName(), baseUri, requestUri,
			getHeaders(request), new ChannelBufferInputStream(
					request.getContent()));
	application.handleRequest(cRequest, new Writer(e.getChannel()));
}
 
Example #12
Source File: StreamChunkAggregator.java    From restcommander with Apache License 2.0 4 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    Object msg = e.getMessage();
    if (!(msg instanceof HttpMessage) && !(msg instanceof HttpChunk)) {
        ctx.sendUpstream(e);
        return;
    }

    HttpMessage currentMessage = this.currentMessage;
    File localFile = this.file;
    if (currentMessage == null) {
        HttpMessage m = (HttpMessage) msg;
        if (m.isChunked()) {
            final String localName = UUID.randomUUID().toString();
            // A chunked message - remove 'Transfer-Encoding' header,
            // initialize the cumulative buffer, and wait for incoming chunks.
            List<String> encodings = m.getHeaders(HttpHeaders.Names.TRANSFER_ENCODING);
            encodings.remove(HttpHeaders.Values.CHUNKED);
            if (encodings.isEmpty()) {
                m.removeHeader(HttpHeaders.Names.TRANSFER_ENCODING);
            }
            this.currentMessage = m;
            this.file = new File(Play.tmpDir, localName);
            this.out = new FileOutputStream(file, true);
        } else {
            // Not a chunked message - pass through.
            ctx.sendUpstream(e);
        }
    } else {
        // TODO: If less that threshold then in memory
        // Merge the received chunk into the content of the current message.
        final HttpChunk chunk = (HttpChunk) msg;
        if (maxContentLength != -1 && (localFile.length() > (maxContentLength - chunk.getContent().readableBytes()))) {
            currentMessage.setHeader(HttpHeaders.Names.WARNING, "play.netty.content.length.exceeded");
        } else {
            IOUtils.copyLarge(new ChannelBufferInputStream(chunk.getContent()), this.out);

            if (chunk.isLast()) {
                this.out.flush();
                this.out.close();

                currentMessage.setHeader(
                        HttpHeaders.Names.CONTENT_LENGTH,
                        String.valueOf(localFile.length()));

                currentMessage.setContent(new FileChannelBuffer(localFile));
                this.out = null;
                this.currentMessage = null;
                this.file = null;
                Channels.fireMessageReceived(ctx, currentMessage, e.getRemoteAddress());
            }
        }
    }

}