Example usage for io.netty.handler.codec.http HttpChunkedInput isEndOfInput

List of usage examples for io.netty.handler.codec.http HttpChunkedInput isEndOfInput

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpChunkedInput isEndOfInput.

Prototype

@Override
    public boolean isEndOfInput() throws Exception 

Source Link

Usage

From source file:org.robotbrains.support.web.server.netty.NettyHttpFileUpload.java

License:Apache License

/**
 * Add a new chunk of data to the upload.
 *
 * @param ctx//from  w ww  .  j  ava  2  s.c  o m
 *          the context for the channel handling
 * @param chunk
 *          the chunked data
 *
 * @throws Exception
 *           problem adding chunk
 *
 */
public void addChunk(ChannelHandlerContext ctx, HttpChunkedInput chunk) throws Exception {
    decoder.offer(chunk.readChunk(ctx));
    try {
        while (decoder.hasNext()) {
            InterfaceHttpData data = decoder.next();
            if (data != null) {
                processHttpData(data);
            }
            if (chunk.isEndOfInput()) {
                break;
            }
        }
    } catch (EndOfDataDecoderException e) {
        getLog().error("Error while adding HTTP chunked POST data", e);
    }
}

From source file:org.robotbrains.support.web.server.netty.NettyWebServerHandler.java

License:Apache License

/**
 * handle a chunk.//from   www  .j  ava 2  s  .co m
 *
 * @param context
 *          the channel event context
 * @param chunk
 *          the chunk frame
 */
private void handleHttpChunk(ChannelHandlerContext context, HttpChunkedInput chunk) {
    Long channelId = ((ChannelWithId) context.channel()).getId();
    NettyHttpFileUpload fileUpload = fileUploadHandlers.get(channelId);
    if (fileUpload != null) {
        try {
            fileUpload.addChunk(context, chunk);

            if (chunk.isEndOfInput()) {
                fileUploadHandlers.remove(channelId);

                fileUpload.fileUploadComplete(context);
            }
        } catch (Throwable e) {
            // An error, so don't leave handler around.
            fileUploadHandlers.remove(channelId);

            webServer.getLog().error("Error while processing a chunk of file upload", e);
            sendError(context, HttpResponseStatus.INTERNAL_SERVER_ERROR);
        }
    } else {
        webServer.getLog().warn("Received HTTP chunk for unknown channel");
    }
}