FileDocCategorySizeDatePackage
SocketInputStream.javaAPI DocAndroid 1.5 API2948Wed May 06 22:41:04 BST 2009org.apache.harmony.luni.net

SocketInputStream

public class SocketInputStream extends InputStream
The SocketInputStream supports the streamed reading of bytes from a socket. Multiple streams may be opened on a socket, so care should be taken to manage opened streams and coordinate read operations between threads.

Fields Summary
private final PlainSocketImpl
socket
Constructors Summary
public SocketInputStream(SocketImpl socket)
Constructs a SocketInputStream for the socket. Read operations are forwarded to the socket.

param
socket the socket to be read
see
Socket

        super();
        this.socket = (PlainSocketImpl) socket;
    
Methods Summary
public intavailable()

        return socket.available();
    
public voidclose()

        socket.close();
    
public intread()

        byte[] buffer = new byte[1];
        int result = socket.read(buffer, 0, 1);
        return (-1 == result) ? result : buffer[0] & 0xFF;
    
public intread(byte[] buffer)

        return read(buffer, 0, buffer.length);
    
public intread(byte[] buffer, int offset, int count)

        if (null == buffer) {
            throw new IOException(Msg.getString("K0047"));//$NON-NLS-1$
        }

        if (0 == count) {
            return 0;
        }

        if (0 > offset || offset >= buffer.length) {
            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002e"));//$NON-NLS-1$
        }
        if (0 > count || offset + count > buffer.length) {
            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f"));//$NON-NLS-1$
        }

        return socket.read(buffer, offset, count);
    
public longskip(long n)

        return (0 == n) ? 0 : super.skip(n);