org.apache.http.impl
Class BHttpConnectionBase

java.lang.Object
  extended by org.apache.http.impl.BHttpConnectionBase
All Implemented Interfaces:
org.apache.http.HttpConnection, org.apache.http.HttpInetConnection
Direct Known Subclasses:
DefaultBHttpClientConnection, DefaultBHttpServerConnection

@NotThreadSafe
public class BHttpConnectionBase
extends java.lang.Object
implements org.apache.http.HttpConnection, org.apache.http.HttpInetConnection

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

Since:
4.0

Constructor Summary
protected BHttpConnectionBase(int buffersize, int fragmentSizeHint, java.nio.charset.CharsetDecoder chardecoder, java.nio.charset.CharsetEncoder charencoder, MessageConstraints constraints, org.apache.http.entity.ContentLengthStrategy incomingContentStrategy, org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy)
          Creates new instance of BHttpConnectionBase.
 
Method Summary
protected  boolean awaitInput(int timeout)
           
protected  void bind(java.net.Socket socket)
          Binds this connection to the given Socket.
 void close()
           
protected  java.io.InputStream createInputStream(long len, org.apache.http.io.SessionInputBuffer inbuffer)
           
protected  java.io.OutputStream createOutputStream(long len, org.apache.http.io.SessionOutputBuffer outbuffer)
           
protected  void doFlush()
           
protected  void ensureOpen()
           
 java.net.InetAddress getLocalAddress()
           
 int getLocalPort()
           
 org.apache.http.HttpConnectionMetrics getMetrics()
           
 java.net.InetAddress getRemoteAddress()
           
 int getRemotePort()
           
protected  org.apache.http.io.SessionInputBuffer getSessionInputBuffer()
           
protected  org.apache.http.io.SessionOutputBuffer getSessionOutputBuffer()
           
protected  java.net.Socket getSocket()
           
protected  java.io.InputStream getSocketInputStream(java.net.Socket socket)
           
protected  java.io.OutputStream getSocketOutputStream(java.net.Socket socket)
           
 int getSocketTimeout()
           
protected  void incrementRequestCount()
           
protected  void incrementResponseCount()
           
 boolean isOpen()
           
 boolean isStale()
           
protected  org.apache.http.HttpEntity prepareInput(org.apache.http.HttpMessage message)
           
protected  java.io.OutputStream prepareOutput(org.apache.http.HttpMessage message)
           
 void setSocketTimeout(int timeout)
           
 void shutdown()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BHttpConnectionBase

protected BHttpConnectionBase(int buffersize,
                              int fragmentSizeHint,
                              java.nio.charset.CharsetDecoder chardecoder,
                              java.nio.charset.CharsetEncoder charencoder,
                              MessageConstraints constraints,
                              org.apache.http.entity.ContentLengthStrategy incomingContentStrategy,
                              org.apache.http.entity.ContentLengthStrategy outgoingContentStrategy)
Creates new instance of BHttpConnectionBase.

Parameters:
buffersize - buffer size. Must be a positive number.
fragmentSizeHint - fragment size hint.
chardecoder - decoder to be used for decoding HTTP protocol elements. If null simple type cast will be used for byte to char conversion.
charencoder - encoder to be used for encoding HTTP protocol elements. If null simple type cast will be used for char to byte conversion.
constraints - Message constraints. If null MessageConstraints.DEFAULT will be used.
incomingContentStrategy - incoming content length strategy. If null LaxContentLengthStrategyHC4.INSTANCE will be used.
outgoingContentStrategy - outgoing content length strategy. If null StrictContentLengthStrategyHC4.INSTANCE will be used.
Method Detail

ensureOpen

protected void ensureOpen()
                   throws java.io.IOException
Throws:
java.io.IOException

getSocketInputStream

protected java.io.InputStream getSocketInputStream(java.net.Socket socket)
                                            throws java.io.IOException
Throws:
java.io.IOException

getSocketOutputStream

protected java.io.OutputStream getSocketOutputStream(java.net.Socket socket)
                                              throws java.io.IOException
Throws:
java.io.IOException

bind

protected void bind(java.net.Socket socket)
             throws java.io.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 - the socket.
Throws:
java.io.IOException - in case of an I/O error.

getSessionInputBuffer

protected org.apache.http.io.SessionInputBuffer getSessionInputBuffer()

getSessionOutputBuffer

protected org.apache.http.io.SessionOutputBuffer getSessionOutputBuffer()

doFlush

protected void doFlush()
                throws java.io.IOException
Throws:
java.io.IOException

isOpen

public boolean isOpen()
Specified by:
isOpen in interface org.apache.http.HttpConnection

getSocket

protected java.net.Socket getSocket()

createOutputStream

protected java.io.OutputStream createOutputStream(long len,
                                                  org.apache.http.io.SessionOutputBuffer outbuffer)

prepareOutput

protected java.io.OutputStream prepareOutput(org.apache.http.HttpMessage message)
                                      throws org.apache.http.HttpException
Throws:
org.apache.http.HttpException

createInputStream

protected java.io.InputStream createInputStream(long len,
                                                org.apache.http.io.SessionInputBuffer inbuffer)

prepareInput

protected org.apache.http.HttpEntity prepareInput(org.apache.http.HttpMessage message)
                                           throws org.apache.http.HttpException
Throws:
org.apache.http.HttpException

getLocalAddress

public java.net.InetAddress getLocalAddress()
Specified by:
getLocalAddress in interface org.apache.http.HttpInetConnection

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface org.apache.http.HttpInetConnection

getRemoteAddress

public java.net.InetAddress getRemoteAddress()
Specified by:
getRemoteAddress in interface org.apache.http.HttpInetConnection

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface org.apache.http.HttpInetConnection

setSocketTimeout

public void setSocketTimeout(int timeout)
Specified by:
setSocketTimeout in interface org.apache.http.HttpConnection

getSocketTimeout

public int getSocketTimeout()
Specified by:
getSocketTimeout in interface org.apache.http.HttpConnection

shutdown

public void shutdown()
              throws java.io.IOException
Specified by:
shutdown in interface org.apache.http.HttpConnection
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Specified by:
close in interface org.apache.http.HttpConnection
Throws:
java.io.IOException

awaitInput

protected boolean awaitInput(int timeout)
                      throws java.io.IOException
Throws:
java.io.IOException

isStale

public boolean isStale()
Specified by:
isStale in interface org.apache.http.HttpConnection

incrementRequestCount

protected void incrementRequestCount()

incrementResponseCount

protected void incrementResponseCount()

getMetrics

public org.apache.http.HttpConnectionMetrics getMetrics()
Specified by:
getMetrics in interface org.apache.http.HttpConnection

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object