Build 1.0_r1(from source)

android.net.http
Class AndroidHttpClientConnection

java.lang.Object
  extended by android.net.http.AndroidHttpClientConnection
All Implemented Interfaces:
HttpConnection, HttpInetConnection

public class AndroidHttpClientConnection
extends Object
implements HttpInetConnection, HttpConnection

A alternate class for (@link DefaultHttpClientConnection). It has better performance than DefaultHttpClientConnection


Constructor Summary
AndroidHttpClientConnection()
           
 
Method Summary
 void bind(Socket socket, HttpParams params)
          Bind socket and set HttpParams to AndroidHttpClientConnection
 void close()
          Closes this connection gracefully.
protected  void doFlush()
           
 void flush()
           
 InetAddress getLocalAddress()
           
 int getLocalPort()
           
 HttpConnectionMetrics getMetrics()
          Returns a collection of connection metrcis
 InetAddress getRemoteAddress()
           
 int getRemotePort()
           
 int getSocketTimeout()
          Returns the socket timeout value.
 boolean isOpen()
          Checks if this connection is open.
 boolean isStale()
          Checks whether this connection has gone down.
 StatusLine parseResponseHeader(Headers headers)
          Parses the response headers and adds them to the given headers object, and returns the response StatusLine
 HttpEntity receiveResponseEntity(Headers headers)
          Return the next response entity.
 void sendRequestEntity(HttpEntityEnclosingRequest request)
          Sends the request entity over the connection.
 void sendRequestHeader(HttpRequest request)
          Sends the request line and all headers over the connection.
 void setSocketTimeout(int timeout)
          Sets the socket timeout value.
 void shutdown()
          Force-closes this connection.
 String toString()
          Returns a string containing a concise, human-readable description of the receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AndroidHttpClientConnection

public AndroidHttpClientConnection()
Method Detail

bind

public void bind(Socket socket,
                 HttpParams params)
          throws IOException
Bind socket and set HttpParams to AndroidHttpClientConnection

Parameters:
socket - outgoing socket
params - HttpParams
Throws:
IOException

toString

public String toString()
Description copied from class: Object
Returns a string containing a concise, human-readable description of the receiver.

Overrides:
toString in class Object
Returns:
String a printable representation for the receiver.

isOpen

public boolean isOpen()
Description copied from interface: HttpConnection
Checks if this connection is open.

Specified by:
isOpen in interface HttpConnection
Returns:
true if it is open, false if it is closed.

getLocalAddress

public InetAddress getLocalAddress()
Specified by:
getLocalAddress in interface HttpInetConnection

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface HttpInetConnection

getRemoteAddress

public InetAddress getRemoteAddress()
Specified by:
getRemoteAddress in interface HttpInetConnection

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface HttpInetConnection

setSocketTimeout

public void setSocketTimeout(int timeout)
Description copied from interface: HttpConnection
Sets the socket timeout value.

Specified by:
setSocketTimeout in interface HttpConnection
Parameters:
timeout - timeout value in milliseconds

getSocketTimeout

public int getSocketTimeout()
Description copied from interface: HttpConnection
Returns the socket timeout value.

Specified by:
getSocketTimeout in interface HttpConnection
Returns:
positive value in milliseconds if a timeout is set, 0 if timeout is disabled or -1 if timeout is undefined.

shutdown

public void shutdown()
              throws IOException
Description copied from interface: HttpConnection
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.

Specified by:
shutdown in interface HttpConnection
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: HttpConnection
Closes this connection gracefully. This method will attempt to flush the transmitter's internal 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.

Specified by:
close in interface HttpConnection
Throws:
IOException

sendRequestHeader

public void sendRequestHeader(HttpRequest request)
                       throws HttpException,
                              IOException
Sends the request line and all headers over the connection.

Parameters:
request - the request whose headers to send.
Throws:
HttpException
IOException

sendRequestEntity

public void sendRequestEntity(HttpEntityEnclosingRequest request)
                       throws HttpException,
                              IOException
Sends the request entity over the connection.

Parameters:
request - the request whose entity to send.
Throws:
HttpException
IOException

doFlush

protected void doFlush()
                throws IOException
Throws:
IOException

flush

public void flush()
           throws IOException
Throws:
IOException

parseResponseHeader

public StatusLine parseResponseHeader(Headers headers)
                               throws IOException,
                                      ParseException
Parses the response headers and adds them to the given headers object, and returns the response StatusLine

Parameters:
headers - store parsed header to headers.
Returns:
StatusLine
Throws:
IOException
ParseException
See Also:
HttpClientConnection.receiveResponseHeader()

receiveResponseEntity

public HttpEntity receiveResponseEntity(Headers headers)
Return the next response entity.

Parameters:
headers - contains values for parsing entity
See Also:
HttpClientConnection.receiveResponseEntity(HttpResponse response)

isStale

public boolean 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.

Specified by:
isStale in interface HttpConnection
Returns:
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

getMetrics

public HttpConnectionMetrics getMetrics()
Returns a collection of connection metrcis

Specified by:
getMetrics in interface HttpConnection
Returns:
HttpConnectionMetrics

Build 1.0_r1(from source)

Please submit a feedback, bug or feature