Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.http.conn
Class BasicManagedEntity

    java.lang.Object
      org.apache.http.entity.HttpEntityWrapper
          org.apache.http.conn.BasicManagedEntity

All Implemented Interfaces:
  ConnectionReleaseTrigger, EofSensorWatcher, HttpEntity

    @NotThreadSafe
    public class BasicManagedEntity

extends HttpEntityWrapper
implements ConnectionReleaseTrigger, EofSensorWatcher

An entity that releases a `connection`. A `ManagedClientConnection` will typically not return a managed entity, but you can replace the unmanaged entity in the response with a managed one.

Since:
  4.0

Field Summary
`protected boolean` | `attemptReuse` Whether to keep the connection alive.
`protected ManagedClientConnection` | `managedConn` The connection to release.

Fields inherited from class org.apache.http.entity.HttpEntityWrapper
`wrappedEntity`

Constructor Summary
`BasicManagedEntity(HttpEntity entity, ManagedClientConnection conn, boolean reuse)` Creates a new managed entity that can release a connection.

Method Summary
`void` | `abortConnection()` Releases the connection without the option of keep-alive.
`void` | `consumeContent()` Deprecated. (4.1) Use `EntityUtils.consume(HttpEntity)`
`boolean` | `eofDetected(InputStream wrapped)` Indicates that EOF is detected.
`InputStream` | `getContent()`
`boolean` | `isRepeatable()`
`void` | `releaseConnection()` Releases the connection with the option of keep-alive.
`protected void` | `releaseManagedConnection()` Releases the connection gracefully.
`boolean` | `streamAbort(InputStream wrapped)` Indicates that the `stream` is aborted.
`boolean` | `streamClosed(InputStream wrapped)` Indicates that the `stream` is closed.
`void` | `writeTo(OutputStream outstream)`

Methods inherited from class org.apache.http.entity.HttpEntityWrapper
`getContentEncoding, getContentLength, getContentType, isChunked, isStreaming`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### managedConn

    protected ManagedClientConnection managedConn

  The connection to release.

### attemptReuse

    protected final boolean attemptReuse

  Whether to keep the connection alive.

Constructor Detail

### BasicManagedEntity

    public BasicManagedEntity(HttpEntity entity,
                              ManagedClientConnection conn,
                              boolean reuse)

  Creates a new managed entity that can release a connection.

  Parameters:
    `entity` - the entity of which to wrap the content. Note that the argument entity can no longer be used afterwards, since the content will be taken by this managed entity.
    `conn` - the connection to release
    `reuse` - whether the connection should be re-used

Method Detail

### isRepeatable

    public boolean isRepeatable()

  Specified by:
    `isRepeatable` in interface `HttpEntity`
  Overrides:
    `isRepeatable` in class `HttpEntityWrapper`

### getContent

    public InputStream getContent()
                           throws IOException

  Specified by:
    `getContent` in interface `HttpEntity`
  Overrides:
    `getContent` in class `HttpEntityWrapper`
  Throws:
    `IOException`

### consumeContent

    public void consumeContent()
                        throws IOException

  Deprecated. (4.1) Use `EntityUtils.consume(HttpEntity)`

  Specified by:
    `consumeContent` in interface `HttpEntity`
  Overrides:
    `consumeContent` in class `HttpEntityWrapper`
  Throws:
    `IOException`

### writeTo

    public void writeTo(OutputStream outstream)
                 throws IOException

  Specified by:
    `writeTo` in interface `HttpEntity`
  Overrides:
    `writeTo` in class `HttpEntityWrapper`
  Throws:
    `IOException`

### releaseConnection

    public void releaseConnection()
                           throws IOException

  Description copied from interface: `ConnectionReleaseTrigger`
  Releases the connection with the option of keep-alive. This is a "graceful" release and may cause IO operations for consuming the remainder of a response entity. Use `abortConnection` for a hard release. The connection may be reused as specified by the duration.

  Specified by:
    `releaseConnection` in interface `ConnectionReleaseTrigger`
  Throws:
    `IOException` - in case of an IO problem. The connection will be released anyway.

### abortConnection

    public void abortConnection()
                         throws IOException

  Description copied from interface: `ConnectionReleaseTrigger`
  Releases the connection without the option of keep-alive. This is a "hard" release that implies a shutdown of the connection. Use `ConnectionReleaseTrigger.releaseConnection()` for a graceful release.

  Specified by:
    `abortConnection` in interface `ConnectionReleaseTrigger`
  Throws:
    `IOException` - in case of an IO problem. The connection will be released anyway.

### eofDetected

    public boolean eofDetected(InputStream wrapped)
                        throws IOException

  Description copied from interface: `EofSensorWatcher`
  Indicates that EOF is detected.

  Specified by:
    `eofDetected` in interface `EofSensorWatcher`
  Parameters:
    `wrapped` - the underlying stream which has reached EOF
  Returns:
    `true` if `wrapped` should be closed, `false` if it should be left alone
  Throws:
    `IOException` - in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as if `false` was returned.

### streamClosed

    public boolean streamClosed(InputStream wrapped)
                         throws IOException

  Description copied from interface: `EofSensorWatcher`
  Indicates that the `stream` is closed. This method will be called only if EOF was not detected before closing. Otherwise, `eofDetected` is called.

  Specified by:
    `streamClosed` in interface `EofSensorWatcher`
  Parameters:
    `wrapped` - the underlying stream which has not reached EOF
  Returns:
    `true` if `wrapped` should be closed, `false` if it should be left alone
  Throws:
    `IOException` - in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as if `false` was returned.

### streamAbort

    public boolean streamAbort(InputStream wrapped)
                        throws IOException

  Description copied from interface: `EofSensorWatcher`
  Indicates that the `stream` is aborted. This method will be called only if EOF was not detected before aborting. Otherwise, `eofDetected` is called.

  This method will also be invoked when an input operation causes an IOException to be thrown to make sure the input stream gets shut down.

  Specified by:
    `streamAbort` in interface `EofSensorWatcher`
  Parameters:
    `wrapped` - the underlying stream which has not reached EOF
  Returns:
    `true` if `wrapped` should be closed, `false` if it should be left alone
  Throws:
    `IOException` - in case of an IO problem, for example if the watcher itself closes the underlying stream. The caller will leave the wrapped stream alone, as if `false` was returned.

### releaseManagedConnection

    protected void releaseManagedConnection()
                                     throws IOException

  Releases the connection gracefully. The connection attribute will be nullified. Subsequent invocations are no-ops.

  Throws:
    `IOException` - in case of an IO problem. The connection attribute will be nullified anyway.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1999-2013 The Apache Software Foundation. All Rights Reserved.