FileDocCategorySizeDatePackage
SocketInputBuffer.javaAPI DocAndroid 1.5 API3839Wed May 06 22:41:10 BST 2009org.apache.http.impl.io

SocketInputBuffer

public class SocketInputBuffer extends AbstractSessionInputBuffer
{@link Socket} bound session input buffer.
author
Oleg Kalnichevski
version
$Revision: 560358 $
since
4.0

Fields Summary
private static final Class
SOCKET_TIMEOUT_CLASS
private final Socket
socket
Constructors Summary
public SocketInputBuffer(Socket socket, int buffersize, HttpParams params)

        super();
        if (socket == null) {
            throw new IllegalArgumentException("Socket may not be null");
        }
        this.socket = socket;
        if (buffersize < 0) {
            buffersize = socket.getReceiveBufferSize();
        }
        if (buffersize < 1024) {
            buffersize = 1024;
        }
        init(socket.getInputStream(), buffersize, params);
    
Methods Summary
private static java.lang.ClassSocketTimeoutExceptionClass()
Returns SocketTimeoutExceptionClass or null if the class does not exist.

return
SocketTimeoutExceptionClass, or null if unavailable.


                           
        
        try {
            return Class.forName("java.net.SocketTimeoutException");
        } catch (ClassNotFoundException e) {
            return null;
        }
    
public booleanisDataAvailable(int timeout)

        boolean result = hasBufferedData();
        if (!result) {
            int oldtimeout = this.socket.getSoTimeout();
            try {
                this.socket.setSoTimeout(timeout);
                fillBuffer();
                result = hasBufferedData();
            } catch (InterruptedIOException e) {
                if (!isSocketTimeoutException(e)) {
                    throw e;
                }
            } finally {
                socket.setSoTimeout(oldtimeout);
            }
        }
        return result;
    
private static booleanisSocketTimeoutException(java.io.InterruptedIOException e)

        if (SOCKET_TIMEOUT_CLASS != null) {
            return SOCKET_TIMEOUT_CLASS.isInstance(e);
        } else {
            return true;
        }