Top Description Fields Constructors Methods
org.apache.http.impl

public Class BHttpConnectionBase

extends Object
implements HttpInetConnection
Class Inheritance
All Implemented Interfaces
org.apache.http.HttpInetConnection, org.apache.http.HttpConnection, java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
org.apache.http.impl.DefaultBHttpClientConnection, org.apache.http.impl.DefaultBHttpServerConnection
Imports
java.io.IOException, .InputStream, .OutputStream, java.net.InetAddress, .Socket, .SocketAddress, .SocketException, .SocketTimeoutException, java.nio.charset.CharsetDecoder, .CharsetEncoder, java.util.concurrent.atomic.AtomicReference, org.apache.http.ConnectionClosedException, .Header, .HttpConnectionMetrics, .HttpEntity, .HttpException, .HttpInetConnection, .HttpMessage, org.apache.http.config.MessageConstraints, org.apache.http.entity.BasicHttpEntity, .ContentLengthStrategy, org.apache.http.impl.entity.LaxContentLengthStrategy, .StrictContentLengthStrategy, org.apache.http.impl.io.ChunkedInputStream, .ChunkedOutputStream, .ContentLengthInputStream, .ContentLengthOutputStream, .EmptyInputStream, .HttpTransportMetricsImpl, .IdentityInputStream, .IdentityOutputStream, .SessionInputBufferImpl, .SessionOutputBufferImpl, org.apache.http.io.SessionInputBuffer, .SessionOutputBuffer, org.apache.http.protocol.HTTP, org.apache.http.util.Args, .NetUtils

This class serves as a base for all org.apache.http.HttpConnection implementations and provides functionality common to both client and server HTTP connections.
Since
4.0

Field Summary

Modifier and TypeField and Description
private final HttpConnectionMetricsImpl
private final SessionInputBufferImpl
private final ContentLengthStrategy
private final MessageConstraints
private final SessionOutputBufferImpl
private final ContentLengthStrategy
private final AtomicReference<Socket>

Constructor Summary

AccessConstructor and Description
protected
BHttpConnectionBase(final int
buffer size. Must be a positive number.
bufferSize
,
final int
fragment size hint.
fragmentSizeHint
,
final CharsetDecoder
decoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
charDecoder
,
final CharsetEncoder
encoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.
charEncoder
,
final MessageConstraints
Message constraints. If null MessageConstraints#DEFAULT will be used.
messageConstraints
,
final ContentLengthStrategy
incoming content length strategy. If null LaxContentLengthStrategy#INSTANCE will be used.
incomingContentStrategy
,
final ContentLengthStrategy
outgoing content length strategy. If null StrictContentLengthStrategy#INSTANCE will be used.
outgoingContentStrategy
)

Creates new instance of BHttpConnectionBase.

Method Summary

Modifier and TypeMethod and Description
protected boolean
awaitInput(final int timeout)

protected void
bind(final Socket
the socket.
socket
)

Binds this connection to the given Socket.

public void
close()

Implements org.apache.http.HttpConnection.close.

Closes this connection gracefully.
protected InputStream
createInputStream(final long len, final SessionInputBuffer inBuffer)

protected OutputStream
createOutputStream(final long len, final SessionOutputBuffer outbuffer)

protected void
protected void
private int
fillInputBuffer(final int timeout)

public InetAddress
public int
public HttpConnectionMetrics
getMetrics()

Implements org.apache.http.HttpConnection.getMetrics.

Returns a collection of connection metrics.
public InetAddress
public int
protected SessionInputBuffer
protected SessionOutputBuffer
protected Socket
protected InputStream
protected OutputStream
public int
getSocketTimeout()

Implements org.apache.http.HttpConnection.getSocketTimeout.

Returns the socket timeout value.
protected void
protected void
public boolean
isOpen()

Implements org.apache.http.HttpConnection.isOpen.

Checks if this connection is open.
public boolean
isStale()

Implements org.apache.http.HttpConnection.isStale.

Checks whether this connection has gone down.
protected HttpEntity
prepareInput(final HttpMessage message)

protected OutputStream
prepareOutput(final HttpMessage message)

public void
setSocketTimeout(final int
timeout value in milliseconds
timeout
)

Implements org.apache.http.HttpConnection.setSocketTimeout.

Sets the socket timeout value.
public void
shutdown()

Implements org.apache.http.HttpConnection.shutdown.

Force-closes this connection.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

connMetricsback to summary
private final HttpConnectionMetricsImpl connMetrics
inBufferback to summary
private final SessionInputBufferImpl inBuffer
incomingContentStrategyback to summary
private final ContentLengthStrategy incomingContentStrategy
messageConstraintsback to summary
private final MessageConstraints messageConstraints
outbufferback to summary
private final SessionOutputBufferImpl outbuffer
outgoingContentStrategyback to summary
private final ContentLengthStrategy outgoingContentStrategy
socketHolderback to summary
private final AtomicReference<Socket> socketHolder

Constructor Detail

BHttpConnectionBaseback to summary
protected BHttpConnectionBase(final int bufferSize, final int fragmentSizeHint, final CharsetDecoder charDecoder, final CharsetEncoder charEncoder, final MessageConstraints messageConstraints, final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy)

Creates new instance of BHttpConnectionBase.

Parameters
bufferSize:int

buffer size. Must be a positive number.

fragmentSizeHint:int

fragment size hint.

charDecoder:CharsetDecoder

decoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.

charEncoder:CharsetEncoder

encoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.

messageConstraints:MessageConstraints

Message constraints. If null MessageConstraints#DEFAULT will be used.

incomingContentStrategy:ContentLengthStrategy

incoming content length strategy. If null LaxContentLengthStrategy#INSTANCE will be used.

outgoingContentStrategy:ContentLengthStrategy

outgoing content length strategy. If null StrictContentLengthStrategy#INSTANCE will be used.

Method Detail

awaitInputback to summary
protected boolean awaitInput(final int timeout) throws IOException
bindback to summary
protected void bind(final Socket socket) throws IOException

Binds this connection to the given Socket. This socket will be used by the connection to send and receive data.

After this method's execution the connection status will be reported as open and the isOpen() will return true.

Parameters
socket:Socket

the socket.

Exceptions
IOException:
in case of an I/O error.
closeback to summary
public void close() throws IOException

Implements org.apache.http.HttpConnection.close.

Doc from org.apache.http.HttpConnection.close.

Closes this connection gracefully. This method will attempt to flush the internal output buffer prior to closing the underlying socket. This method MUST NOT be called from a different thread to force shutdown of the connection. Use shutdown instead.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

createInputStreamback to summary
protected InputStream createInputStream(final long len, final SessionInputBuffer inBuffer)
createOutputStreamback to summary
protected OutputStream createOutputStream(final long len, final SessionOutputBuffer outbuffer)
doFlushback to summary
protected void doFlush() throws IOException
ensureOpenback to summary
protected void ensureOpen() throws IOException
fillInputBufferback to summary
private int fillInputBuffer(final int timeout) throws IOException
getLocalAddressback to summary
public InetAddress getLocalAddress()

Implements org.apache.http.HttpInetConnection.getLocalAddress.

Annotations
@Override
getLocalPortback to summary
public int getLocalPort()

Implements org.apache.http.HttpInetConnection.getLocalPort.

Annotations
@Override
getMetricsback to summary
public HttpConnectionMetrics getMetrics()

Implements org.apache.http.HttpConnection.getMetrics.

Doc from org.apache.http.HttpConnection.getMetrics.

Returns a collection of connection metrics.

Returns:HttpConnectionMetrics

HttpConnectionMetrics

Annotations
@Override
getRemoteAddressback to summary
public InetAddress getRemoteAddress()

Implements org.apache.http.HttpInetConnection.getRemoteAddress.

Annotations
@Override
getRemotePortback to summary
public int getRemotePort()

Implements org.apache.http.HttpInetConnection.getRemotePort.

Annotations
@Override
getSessionInputBufferback to summary
protected SessionInputBuffer getSessionInputBuffer()
getSessionOutputBufferback to summary
protected SessionOutputBuffer getSessionOutputBuffer()
getSocketback to summary
protected Socket getSocket()
getSocketInputStreamback to summary
protected InputStream getSocketInputStream(final Socket socket) throws IOException
getSocketOutputStreamback to summary
protected OutputStream getSocketOutputStream(final Socket socket) throws IOException
getSocketTimeoutback to summary
public int getSocketTimeout()

Implements org.apache.http.HttpConnection.getSocketTimeout.

Doc from org.apache.http.HttpConnection.getSocketTimeout.

Returns the socket timeout value.

Returns:int

positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

Annotations
@Override
incrementRequestCountback to summary
protected void incrementRequestCount()
incrementResponseCountback to summary
protected void incrementResponseCount()
isOpenback to summary
public boolean isOpen()

Implements org.apache.http.HttpConnection.isOpen.

Doc from org.apache.http.HttpConnection.isOpen.

Checks if this connection is open.

Returns:boolean

true if it is open, false if it is closed.

Annotations
@Override
isStaleback to summary
public boolean isStale()

Implements org.apache.http.HttpConnection.isStale.

Doc from org.apache.http.HttpConnection.isStale.

Checks whether this connection has gone down. Network connections may get closed during some time of inactivity for several reasons. The next time a read is attempted on such a connection it will throw an IOException. This method tries to alleviate this inconvenience by trying to find out if a connection is still usable. Implementations may do that by attempting a read with a very small timeout. Thus this method may block for a small amount of time before returning a result. It is therefore an expensive operation.

Returns:boolean

true if attempts to use this connection are likely to succeed, or false if they are likely to fail and this connection should be closed

Annotations
@Override
prepareInputback to summary
protected HttpEntity prepareInput(final HttpMessage message) throws HttpException
prepareOutputback to summary
protected OutputStream prepareOutput(final HttpMessage message) throws HttpException
setSocketTimeoutback to summary
public void setSocketTimeout(final int timeout)

Implements org.apache.http.HttpConnection.setSocketTimeout.

Doc from org.apache.http.HttpConnection.setSocketTimeout.

Sets the socket timeout value.

Parameters
timeout:int

timeout value in milliseconds

Annotations
@Override
shutdownback to summary
public void shutdown() throws IOException

Implements org.apache.http.HttpConnection.shutdown.

Doc from org.apache.http.HttpConnection.shutdown.

Force-closes this connection. This is the only method of a connection which may be called from a different thread to terminate the connection. This method will not attempt to flush the transmitter's internal buffer prior to closing the underlying socket.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override