java.net
Class SocketInputStream

java.lang.Object
  |
  +--java.io.InputStream
        |
        +--java.io.FileInputStream
              |
              +--java.net.SocketInputStream

class SocketInputStream
extends FileInputStream


Field Summary
private  boolean closing
          Closes the stream.
private  boolean eof
           
private  PlainSocketImpl impl
           
private  Socket socket
           
private  byte[] temp
           
 
Fields inherited from class java.io.FileInputStream
 
Fields inherited from class java.io.InputStream
 
Constructor Summary
(package private) SocketInputStream(PlainSocketImpl impl)
          Creates a new SocketInputStream.
 
Method Summary
 int available()
          Returns the number of bytes that can be read without blocking.
 void close()
          Enabled: Closes this file input stream and releases any system resources associated with the stream.
protected  void finalize()
          Overrides finalize, the fd is closed by the Socket.
 java.nio.channels.FileChannel getChannel()
          Returns the unique FileChannel object associated with this file input stream.
private static void init()
          Perform class load-time initializations.
 int read()
          Reads a single byte from the socket.
 int read(byte[] b)
          Reads into a byte array data from the socket.
 int read(byte[] b, int off, int length)
          Reads into a byte array b at offset off, length bytes of data.
(package private)  void setEOF(boolean eof)
           
 long skip(long numbytes)
          Skips n bytes of input.
private  int socketRead0(FileDescriptor fd, byte[] b, int off, int len, int timeout)
          Reads into an array of bytes at the specified offset using the received socket primitive.
 
Methods inherited from class java.io.FileInputStream
getFD
 
Methods inherited from class java.io.InputStream
__printOn, getCryptoHash, mark, markSupported, readAvailable, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eof

private boolean eof

impl

private PlainSocketImpl impl

temp

private byte[] temp

socket

private Socket socket

closing

private boolean closing
Closes the stream.

Constructor Detail

SocketInputStream

SocketInputStream(PlainSocketImpl impl)
            throws IOException
Creates a new SocketInputStream. Can only be called by a Socket. This method needs to hang on to the owner Socket so that the fd will not be closed.

Parameters:
impl - the implemented socket input stream
Method Detail

getChannel

public final java.nio.channels.FileChannel getChannel()
Returns the unique FileChannel object associated with this file input stream.

The getChannel method of SocketInputStream returns null since it is a socket based stream.

Overrides:
getChannel in class FileInputStream
Returns:
the file channel associated with this file input stream
Since:
1.4

socketRead0

private int socketRead0(FileDescriptor fd,
                        byte[] b,
                        int off,
                        int len,
                        int timeout)
                 throws IOException
Reads into an array of bytes at the specified offset using the received socket primitive.

Parameters:
fd - the FileDescriptor
b - the buffer into which the data is read
off - the start offset of the data
len - the maximum number of bytes read
timeout - the read timeout in ms
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
IOException

read

public int read(byte[] b)
         throws IOException
Reads into a byte array data from the socket.

Overrides:
read in class FileInputStream
Parameters:
b - the buffer into which the data is read
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
IOException

read

public int read(byte[] b,
                int off,
                int length)
         throws IOException
Reads into a byte array b at offset off, length bytes of data.

Overrides:
read in class FileInputStream
Parameters:
b - the buffer into which the data is read
off - the start offset of the data
length - the maximum number of bytes read.
Returns:
the actual number of bytes read, -1 is returned when the end of the stream is reached.
IOException

read

public int read()
         throws IOException
Reads a single byte from the socket.

Overrides:
read in class FileInputStream
Returns:
the next byte of data, or -1 if the end of the file is reached.
IOException

skip

public long skip(long numbytes)
          throws IOException
Skips n bytes of input.

Overrides:
skip in class FileInputStream
Parameters:
numbytes - the number of bytes to be skipped.
Returns:
the actual number of bytes skipped.
IOException

available

public int available()
              throws IOException
Returns the number of bytes that can be read without blocking.

Overrides:
available in class FileInputStream
Returns:
the number of immediately available bytes
IOException

close

public void close()
           throws IOException
Description copied from class: FileInputStream
Enabled: Closes this file input stream and releases any system resources associated with the stream.

If this stream has an associated channel then the channel is closed as well.

Overrides:
close in class FileInputStream
IOException

setEOF

void setEOF(boolean eof)

finalize

protected void finalize()
Overrides finalize, the fd is closed by the Socket.

Overrides:
finalize in class FileInputStream
See Also:
java.io.FileInputStream#close()

init

private static void init()
Perform class load-time initializations.



comments?