Android APIs
Added in API level 1
Deprecated since API level 22
public interface

HttpConnection

org.apache.http.HttpConnection
Known Indirect Subclasses

This interface was deprecated in API level 22.
Please use openConnection() instead. Please visit this webpage for further details.

Class Overview

A generic HTTP connection, useful on client and server side.

Summary

Public Methods
abstract void close()
Closes this connection gracefully.
abstract HttpConnectionMetrics getMetrics()
Returns a collection of connection metrcis
abstract int getSocketTimeout()
Returns the socket timeout value.
abstract boolean isOpen()
Checks if this connection is open.
abstract boolean isStale()
Checks whether this connection has gone down.
abstract void setSocketTimeout(int timeout)
Sets the socket timeout value.
abstract void shutdown()
Force-closes this connection.

Public Methods

public abstract void close ()

Added in API level 1

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.

Throws
IOException

public abstract HttpConnectionMetrics getMetrics ()

Added in API level 1

Returns a collection of connection metrcis

Returns
  • HttpConnectionMetrics

public abstract int getSocketTimeout ()

Added in API level 1

Returns the socket timeout value.

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

public abstract boolean isOpen ()

Added in API level 1

Checks if this connection is open.

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

public abstract boolean isStale ()

Added in API level 1

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
  • 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

public abstract void setSocketTimeout (int timeout)

Added in API level 1

Sets the socket timeout value.

Parameters
timeout timeout value in milliseconds

public abstract void shutdown ()

Added in API level 1

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.

Throws
IOException