org.simpleframework.http.message
Class EntityConsumer

java.lang.Object
  extended by org.simpleframework.http.message.EntityConsumer
All Implemented Interfaces:
ByteConsumer

public class EntityConsumer
extends Object
implements ByteConsumer

The EntityConsumer object is used to consume data from a cursor and build a request entity. Each constituent part of the entity is consumed from the pipeline and can be acquired from this consumer object. The Header and Body can be used to extract the individual parts of the entity.

Author:
Niall Gallagher

Field Summary
protected  BodyConsumer body
          This is used to consume the body for the request entity.
protected  org.simpleframework.http.message.ContinueDispatcher dispatcher
          This is used to determine if there a continue is expected.
protected  org.simpleframework.http.message.ConsumerFactory factory
          This is used to create a body consumer for the entity.
protected  RequestConsumer header
          This is used to consume the header for the request entity.
protected  Trace trace
          This is used to trace the progress of the request consumption.
 
Constructor Summary
EntityConsumer(Allocator allocator, Channel channel)
          Constructor for the EntityConsumer object.
 
Method Summary
 void consume(ByteCursor cursor)
          This consumes the header and body from the cursor.
 Body getBody()
          This is used to acquire the body for this HTTP entity.
 Header getHeader()
          This provides the HTTP request header for the entity.
 boolean isFinished()
          This is determined finished when the body has been consumed.
 boolean isHeaderFinished()
          This is used to determine if the header has finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dispatcher

protected org.simpleframework.http.message.ContinueDispatcher dispatcher
This is used to determine if there a continue is expected.


factory

protected org.simpleframework.http.message.ConsumerFactory factory
This is used to create a body consumer for the entity.


header

protected RequestConsumer header
This is used to consume the header for the request entity.


body

protected BodyConsumer body
This is used to consume the body for the request entity.


trace

protected Trace trace
This is used to trace the progress of the request consumption.

Constructor Detail

EntityConsumer

public EntityConsumer(Allocator allocator,
                      Channel channel)
Constructor for the EntityConsumer object. This is used to build an entity from the constituent parts. Once all of the parts have been consumed they are available from the exposed methods of this consumed instance.

Parameters:
allocator - this is used to allocate the memory used
channel - this is the channel used to send a response
Method Detail

getBody

public Body getBody()
This is used to acquire the body for this HTTP entity. This will return a body which can be used to read the content of the message, also if the request is multipart upload then all of the parts are provided as Attachment objects. Each part can then be read as an individual message.

Returns:
the body provided by the HTTP request message

getHeader

public Header getHeader()
This provides the HTTP request header for the entity. This is always populated and provides the details sent by the client such as the target URI and the query if specified. Also this can be used to determine the method and protocol version used.

Returns:
the header provided by the HTTP request message

consume

public void consume(ByteCursor cursor)
             throws IOException
This consumes the header and body from the cursor. The header is consumed first followed by the body if there is any. There is a body of there is a Content-Length or a Transfer-Encoding header present. If there is no body then a substitute body is given which has an empty input stream.

Specified by:
consume in interface ByteConsumer
Parameters:
cursor - used to consumed the bytes for the entity
Throws:
IOException

isFinished

public boolean isFinished()
This is determined finished when the body has been consumed. If only the header has been consumed then the body will be created using the header information, the body is then read from the cursor, which may read nothing for an empty body.

Specified by:
isFinished in interface ByteConsumer
Returns:
this returns true if the entity has been built

isHeaderFinished

public boolean isHeaderFinished()
This is used to determine if the header has finished. Exposing this method ensures the entity consumer can be used to determine if the header for the entity can be consumed before fully processing the entity body of the request message.

Returns:
determines if the header has been fully consumed


Copyright © 2014. All Rights Reserved.