org.apache.http.nio.entity
Class ConsumingNHttpEntityTemplate

java.lang.Object
  extended by org.apache.http.entity.HttpEntityWrapper
      extended by org.apache.http.nio.entity.ConsumingNHttpEntityTemplate
All Implemented Interfaces:
HttpEntity, ConsumingNHttpEntity

public class ConsumingNHttpEntityTemplate
extends HttpEntityWrapper
implements ConsumingNHttpEntity

A ConsumingNHttpEntity that forwards available content to a ContentListener.


Field Summary
 
Fields inherited from class org.apache.http.entity.HttpEntityWrapper
wrappedEntity
 
Constructor Summary
ConsumingNHttpEntityTemplate(HttpEntity httpEntity, ContentListener contentListener)
           
 
Method Summary
 void consumeContent()
          TODO: The name of this method is misnomer.
 void consumeContent(ContentDecoder decoder, IOControl ioctrl)
          Notification that content is available to be read from the decoder.
 void finish()
          Notification that any resources allocated for reading can be released.
 java.io.InputStream getContent()
          Creates a new InputStream object of the entity.
 ContentListener getContentListener()
           
 boolean isStreaming()
          Tells whether this entity depends on an underlying stream.
 void writeTo(java.io.OutputStream out)
          Writes the entity content to the output stream.
 
Methods inherited from class org.apache.http.entity.HttpEntityWrapper
getContentEncoding, getContentLength, getContentType, isChunked, isRepeatable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.http.HttpEntity
getContentEncoding, getContentLength, getContentType, isChunked, isRepeatable
 

Constructor Detail

ConsumingNHttpEntityTemplate

public ConsumingNHttpEntityTemplate(HttpEntity httpEntity,
                                    ContentListener contentListener)
Method Detail

getContentListener

public ContentListener getContentListener()

getContent

public java.io.InputStream getContent()
                               throws java.io.IOException,
                                      java.lang.IllegalStateException
Description copied from interface: HttpEntity
Creates a new InputStream object of the entity. It is a programming error to return the same InputStream object more than once. Entities that are not repeatable will throw an exception if this method is called multiple times.

Specified by:
getContent in interface HttpEntity
Overrides:
getContent in class HttpEntityWrapper
Returns:
a new input stream that returns the entity data.
Throws:
java.io.IOException - if the stream could not be created
java.lang.IllegalStateException - if this entity is not repeatable and the stream has already been obtained previously

isStreaming

public boolean isStreaming()
Description copied from interface: HttpEntity
Tells whether this entity depends on an underlying stream. Streamed entities should return true until the content has been consumed, false afterwards. Self-contained entities should return false. Wrapping entities should delegate this call to the wrapped entity.
The content of a streamed entity is consumed when the stream returned by getContent has been read to EOF, or after consumeContent has been called. If a streamed entity can not detect whether the stream has been read to EOF, it should return true until consumeContent is called.

Specified by:
isStreaming in interface HttpEntity
Overrides:
isStreaming in class HttpEntityWrapper
Returns:
true if the entity content is streamed and not yet consumed, false otherwise

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Description copied from interface: HttpEntity
Writes the entity content to the output stream.

Specified by:
writeTo in interface HttpEntity
Overrides:
writeTo in class HttpEntityWrapper
Parameters:
out - the output stream to write entity content to
Throws:
java.io.IOException - if an I/O error occurs

consumeContent

public void consumeContent()
                    throws java.io.IOException,
                           java.lang.UnsupportedOperationException
Description copied from interface: HttpEntity
TODO: The name of this method is misnomer. It will be renamed to #finish() in the next major release.
This method is called to indicate that the content of this entity is no longer required. All entity implementations are expected to release all allocated resources as a result of this method invocation. Content streaming entities are also expected to dispose of the remaining content, if any. Wrapping entities should delegate this call to the wrapped entity.
This method is of particular importance for entities being received from a connection. The entity needs to be consumed completely in order to re-use the connection with keep-alive.

Specified by:
consumeContent in interface HttpEntity
Overrides:
consumeContent in class HttpEntityWrapper
Throws:
java.io.IOException - if an I/O error occurs. This indicates that connection keep-alive is not possible.
java.lang.UnsupportedOperationException

consumeContent

public void consumeContent(ContentDecoder decoder,
                           IOControl ioctrl)
                    throws java.io.IOException
Description copied from interface: ConsumingNHttpEntity
Notification that content is available to be read from the decoder.

Specified by:
consumeContent in interface ConsumingNHttpEntity
Throws:
java.io.IOException

finish

public void finish()
Description copied from interface: ConsumingNHttpEntity
Notification that any resources allocated for reading can be released.

Specified by:
finish in interface ConsumingNHttpEntity


Copyright © 2005-2008 Apache Software Foundation. All Rights Reserved.