com.caucho.vfs
Class SocketChannelStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.vfs.SocketChannelStream

@Module
public class SocketChannelStream
extends StreamImpl

Specialized stream to handle sockets.

Unlike VfsStream, when the read() throws and IOException or a SocketException, SocketStream will throw a ClientDisconnectException.


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Constructor Summary
SocketChannelStream()
           
SocketChannelStream(java.nio.channels.SocketChannel channel)
           
 
Method Summary
 boolean canRead()
          Returns true since the socket stream can be read.
 void close()
          Closes the underlying sockets and socket streams.
 int getAvailable()
          Returns the number of bytes available to be read from the input stream.
 byte[] getNewline()
          Returns the stream's natural newline character.
 boolean getThrowReadInterrupts()
          If true, throws read interrupts instead of returning an end of fail.
 boolean hasSkip()
          Returns true if stream is readable and bytes can be skipped.
 void init(java.nio.channels.SocketChannel channel)
          Initialize the SocketStream with a new Socket.
 int read(byte[] buf, int offset, int length)
          Reads bytes from the socket.
 void setNewline(byte[] newline)
           
 void setThrowReadInterrupts(boolean allowThrow)
          If true, throws read interrupts instead of returning an end of fail.
 java.lang.String toString()
           
 
Methods inherited from class com.caucho.vfs.StreamImpl
canWrite, clearWrite, closeWrite, flush, flushBuffer, flushToDisk, getAttribute, getAttributeNames, getFlushOnNewline, getPath, getReadBuffer, getReadPosition, isClosed, isEof, readNonBlock, readTimeout, removeAttribute, seekEnd, seekStart, setAttribute, setPath, setWriteEncoding, skip, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SocketChannelStream

public SocketChannelStream()

SocketChannelStream

public SocketChannelStream(java.nio.channels.SocketChannel channel)
Method Detail

init

public void init(java.nio.channels.SocketChannel channel)
Initialize the SocketStream with a new Socket.

Parameters:
s - the new socket.

setThrowReadInterrupts

public void setThrowReadInterrupts(boolean allowThrow)
If true, throws read interrupts instead of returning an end of fail. Defaults to false.


getThrowReadInterrupts

public boolean getThrowReadInterrupts()
If true, throws read interrupts instead of returning an end of fail. Defaults to false.


setNewline

public void setNewline(byte[] newline)

getNewline

public byte[] getNewline()
Description copied from class: StreamImpl
Returns the stream's natural newline character.

Overrides:
getNewline in class StreamImpl

hasSkip

public boolean hasSkip()
Returns true if stream is readable and bytes can be skipped.

Overrides:
hasSkip in class StreamImpl

canRead

public boolean canRead()
Returns true since the socket stream can be read.

Overrides:
canRead in class StreamImpl

read

public int read(byte[] buf,
                int offset,
                int length)
         throws java.io.IOException
Reads bytes from the socket.

Overrides:
read in class StreamImpl
Parameters:
buf - byte buffer receiving the bytes
offset - offset into the buffer
length - number of bytes to read
Returns:
number of bytes read or -1
Throws:
throws - ClientDisconnectException if the connection is dropped
java.io.IOException

getAvailable

public int getAvailable()
                 throws java.io.IOException
Returns the number of bytes available to be read from the input stream.

Overrides:
getAvailable in class StreamImpl
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the underlying sockets and socket streams.

Overrides:
close in class StreamImpl
Throws:
java.io.IOException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object