Package org.jboss.netty.handler.codec.http

Examples of org.jboss.netty.handler.codec.http.DefaultHttpChunk


      HttpResponse httpres = buildHttpResponse(res);
      localHandler.handleResponse(this, httpres);
      if (httpres.isChunked())
      {
        Buffer content = res.content;
        HttpChunk chunk = new DefaultHttpChunk(
                ChannelBuffers.wrappedBuffer(content.getRawBuffer(),
                        content.getReadIndex(), content.readableBytes()));
        localHandler.handleChunk(this, chunk);
      }
    }
View Full Code Here


  @Override
  public void onRangeChunk(Buffer buf)
  {
    if (null != localHandler)
    {
      HttpChunk chunk = new DefaultHttpChunk(
              ChannelBuffers.wrappedBuffer(buf.getRawBuffer(),
                      buf.getReadIndex(), buf.readableBytes()));
      localHandler.handleChunk(this, chunk);
    }
    else
View Full Code Here

    }
    local.handleResponse(this, httpres);
    if (httpres.isChunked())
    {
      Buffer content = res.content;
      HttpChunk chunk = new DefaultHttpChunk(
              ChannelBuffers.wrappedBuffer(content.getRawBuffer(),
                      content.getReadIndex(), content.readableBytes()));
      local.handleChunk(this, chunk);
    }
  }
View Full Code Here

  @Override
  public void onRangeChunk(Buffer buf)
  {
    if (null != local)
    {
      HttpChunk chunk = new DefaultHttpChunk(
              ChannelBuffers.wrappedBuffer(buf.getRawBuffer(),
                      buf.getReadIndex(), buf.readableBytes()));
      local.handleChunk(this, chunk);
    }
    else
View Full Code Here

            return reset();
        }
        case READ_VARIABLE_LENGTH_CONTENT_AS_CHUNKS: {
            // Keep reading data as a chunk until the end of connection is reached.
            int chunkSize = Math.min(maxChunkSize, buffer.readableBytes());
            HttpChunk chunk = new DefaultHttpChunk(buffer.readBytes(chunkSize));

            if (!buffer.readable()) {
                // Reached to the end of the connection.
                reset();
                if (!chunk.isLast()) {
                    // Append the last chunk.
                    return new Object[] { chunk, HttpChunk.LAST_CHUNK };
                }
            }
            return chunk;
        }
        case READ_FIXED_LENGTH_CONTENT: {
            //we have a content-length so we just read the correct number of bytes
            readFixedLengthContent(buffer);
            return reset();
        }
        case READ_FIXED_LENGTH_CONTENT_AS_CHUNKS: {
            long chunkSize = this.chunkSize;
            HttpChunk chunk;
            if (chunkSize > maxChunkSize) {
                chunk = new DefaultHttpChunk(buffer.readBytes(maxChunkSize));
                chunkSize -= maxChunkSize;
            } else {
                assert chunkSize <= Integer.MAX_VALUE;
                chunk = new DefaultHttpChunk(buffer.readBytes((int) chunkSize));
                chunkSize = 0;
            }
            this.chunkSize = chunkSize;

            if (chunkSize == 0) {
                // Read all content.
                reset();
                if (!chunk.isLast()) {
                    // Append the last chunk.
                    return new Object[] { chunk, HttpChunk.LAST_CHUNK };
                }
            }
            return chunk;
        }
        /**
         * everything else after this point takes care of reading chunked content. basically, read chunk size,
         * read chunk, read and ignore the CRLF and repeat until 0
         */
        case READ_CHUNK_SIZE: {
            String line = readLine(buffer, maxInitialLineLength);
            int chunkSize = getChunkSize(line);
            this.chunkSize = chunkSize;
            if (chunkSize == 0) {
                checkpoint(State.READ_CHUNK_FOOTER);
                return null;
            } else if (chunkSize > maxChunkSize) {
                // A chunk is too large. Split them into multiple chunks again.
                checkpoint(State.READ_CHUNKED_CONTENT_AS_CHUNKS);
            } else {
                checkpoint(State.READ_CHUNKED_CONTENT);
            }
        }
        case READ_CHUNKED_CONTENT: {
            assert chunkSize <= Integer.MAX_VALUE;
            HttpChunk chunk = new DefaultHttpChunk(buffer.readBytes((int) chunkSize));
            checkpoint(State.READ_CHUNK_DELIMITER);
            return chunk;
        }
        case READ_CHUNKED_CONTENT_AS_CHUNKS: {
            long chunkSize = this.chunkSize;
            HttpChunk chunk;
            if (chunkSize > maxChunkSize) {
                chunk = new DefaultHttpChunk(buffer.readBytes(maxChunkSize));
                chunkSize -= maxChunkSize;
            } else {
                assert chunkSize <= Integer.MAX_VALUE;
                chunk = new DefaultHttpChunk(buffer.readBytes((int) chunkSize));
                chunkSize = 0;
            }
            this.chunkSize = chunkSize;

            if (chunkSize == 0) {
                // Read all content.
                checkpoint(State.READ_CHUNK_DELIMITER);
            }

            if (!chunk.isLast()) {
                return chunk;
            }
        }
        case READ_CHUNK_DELIMITER: {
            for (;;) {
View Full Code Here

                    "--" + boundary + "--\r\n";

            // Create decoder instance to test.
            final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);

            decoder.offer(new DefaultHttpChunk(ChannelBuffers.copiedBuffer(body, CharsetUtil.UTF_8)));
            decoder.offer(new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER));

            // Validate it's enough chunks to decode upload.
            assertTrue(decoder.hasNext());

            // Decode binary upload.
View Full Code Here

        if (currentBuffer.readableBytes() < HttpPostBodyUtil.chunkSize) {
            currentData = null;
            return null;
        }
        buffer = fillChannelBuffer();
        return new DefaultHttpChunk(buffer);
    }
View Full Code Here

                //continue
                size -= buffer.readableBytes() + 1;
            }
            if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {
                buffer = fillChannelBuffer();
                return new DefaultHttpChunk(buffer);
            }
        }
        try {
            buffer = ((HttpData) currentData).getChunk(size);
        } catch (IOException e) {
            throw new ErrorDataEncoderException(e);
        }
        ChannelBuffer delimiter = null;
        if (buffer.readableBytes() < size) {
            // delimiter
            isKey = true;
            delimiter = iterator.hasNext() ?
                    ChannelBuffers.wrappedBuffer("&".getBytes()) :
                        null;
        }
        if (buffer.capacity() == 0) {
            // end for current InterfaceHttpData, need potentially more data
            currentData = null;
            if (currentBuffer == null) {
                currentBuffer = delimiter;
            } else {
                if (delimiter != null) {
                    currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer,
                        delimiter);
                }
            }
            if (currentBuffer.readableBytes() >= HttpPostBodyUtil.chunkSize) {
                buffer = fillChannelBuffer();
                return new DefaultHttpChunk(buffer);
            }
            return null;
        }
        if (currentBuffer == null) {
            if (delimiter != null) {
                currentBuffer = ChannelBuffers.wrappedBuffer(buffer,
                    delimiter);
            } else {
                currentBuffer = buffer;
            }
        } else {
            if (delimiter != null) {
                currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer,
                    buffer, delimiter);
            } else {
                currentBuffer = ChannelBuffers.wrappedBuffer(currentBuffer,
                        buffer);
            }
        }
        if (currentBuffer.readableBytes() < HttpPostBodyUtil.chunkSize) {
            // end for current InterfaceHttpData, need more data
            currentData = null;
            isKey = true;
            return null;
        }
        buffer = fillChannelBuffer();
        // size = 0
        return new DefaultHttpChunk(buffer);
    }
View Full Code Here

     * @throws ErrorDataEncoderException if the encoding is in error
     */
    public HttpChunk nextChunk() throws ErrorDataEncoderException {
        if (isLastChunk) {
            isLastChunkSent = true;
            return new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER);
        }
        ChannelBuffer buffer;
        int size = HttpPostBodyUtil.chunkSize;
        // first test if previous buffer is not empty
        if (currentBuffer != null) {
            size -= currentBuffer.readableBytes();
        }
        if (size <= 0) {
            //NextChunk from buffer
            buffer = fillChannelBuffer();
            return new DefaultHttpChunk(buffer);
        }
        // size > 0
        if (currentData != null) {
            // continue to read data
            if (isMultipart) {
                HttpChunk chunk = encodeNextChunkMultipart(size);
                if (chunk != null) {
                    return chunk;
                }
            } else {
                HttpChunk chunk = encodeNextChunkUrlEncoded(size);
                if (chunk != null) {
                    //NextChunk Url from currentData
                    return chunk;
                }
            }
            size = HttpPostBodyUtil.chunkSize - currentBuffer.readableBytes();
        }
        if (! iterator.hasNext()) {
            isLastChunk = true;
            //NextChunk as last non empty from buffer
            buffer = currentBuffer;
            currentBuffer = null;
            return new DefaultHttpChunk(buffer);
        }
        while (size > 0 && iterator.hasNext()) {
            currentData = iterator.next();
            HttpChunk chunk;
            if (isMultipart) {
                chunk = encodeNextChunkMultipart(size);
            } else {
                chunk = encodeNextChunkUrlEncoded(size);
            }
            if (chunk == null) {
                // not enough
                size = HttpPostBodyUtil.chunkSize - currentBuffer.readableBytes();
                continue;
            }
            //NextChunk from data
            return chunk;
        }
        // end since no more data
        isLastChunk = true;
        if (currentBuffer == null) {
            isLastChunkSent = true;
            //LastChunk with no more data
            return new DefaultHttpChunk(ChannelBuffers.EMPTY_BUFFER);
        }
        //Previous LastChunk with no more data
        buffer = currentBuffer;
        currentBuffer = null;
        return new DefaultHttpChunk(buffer);
    }
View Full Code Here

    }

    @Override
    public NettyHttpResponse write(String content) {
        if (response.isChunked()) {
            ctx.getChannel().write(new DefaultHttpChunk(wrappedBuffer(content.getBytes(CharsetUtil.UTF_8))))
        } else {
            write(copiedBuffer(content, CharsetUtil.UTF_8));
        }   
        return this;
    }
View Full Code Here

TOP

Related Classes of org.jboss.netty.handler.codec.http.DefaultHttpChunk

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.