com.caucho.vfs
Class DatagramStream

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

public class DatagramStream
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
DatagramStream(java.net.DatagramSocket s)
           
 
Method Summary
 boolean canRead()
          Returns true since the socket stream can be read.
 boolean canWrite()
          Returns true if this is a writable stream.
 void close()
          Closes the underlying sockets and socket streams.
 void closeWrite()
          Closes the write half of the stream.
 int getAvailable()
          Returns the number of bytes available to be read from the input stream.
 java.io.InputStream getInputStream()
           
 java.io.OutputStream getOutputStream()
           
 long getPosition()
          Returns the position.
 boolean getThrowReadInterrupts()
          If true, throws read interrupts instead of returning an end of fail.
 long getTotalReadBytes()
           
 long getTotalWriteBytes()
           
 boolean hasSkip()
          Returns true if stream is readable and bytes can be skipped.
 int read(byte[] buf, int offset, int length)
          Reads bytes from the socket.
 int readTimeout(byte[] buf, int offset, int length, long timeout)
          Reads bytes from the socket.
 void resetTotalBytes()
          Flushes the socket.
 boolean setPosition(long offset)
           
 void setThrowReadInterrupts(boolean allowThrow)
          If true, throws read interrupts instead of returning an end of fail.
 long skip(long n)
          Skips bytes in the file.
 void unread()
          Unread the last byte.
 void write(byte[] buf, int offset, int length, boolean isEnd)
          Writes bytes to the socket.
 
Methods inherited from class com.caucho.vfs.StreamImpl
clearWrite, flush, flushBuffer, flushToDisk, getAttribute, getAttributeNames, getFlushOnNewline, getNewline, getPath, getReadBuffer, getReadPosition, isClosed, isEof, readNonBlock, removeAttribute, seekEnd, seekStart, setAttribute, setPath, setWriteEncoding, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatagramStream

public DatagramStream(java.net.DatagramSocket s)
Method Detail

getInputStream

public java.io.InputStream getInputStream()

getOutputStream

public java.io.OutputStream getOutputStream()

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.


getPosition

public long getPosition()
Returns the position.


setPosition

public boolean setPosition(long offset)

unread

public void unread()
            throws java.io.IOException
Unread the last byte.

Throws:
java.io.IOException

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

skip

public long skip(long n)
          throws java.io.IOException
Skips bytes in the file.

Overrides:
skip in class StreamImpl
Parameters:
n - the number of bytes to skip
Returns:
the actual bytes skipped.
Throws:
java.io.IOException

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

readTimeout

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

Overrides:
readTimeout 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

canWrite

public boolean canWrite()
Description copied from class: StreamImpl
Returns true if this is a writable stream.

Overrides:
canWrite in class StreamImpl

write

public void write(byte[] buf,
                  int offset,
                  int length,
                  boolean isEnd)
           throws java.io.IOException
Writes bytes to the socket.

Overrides:
write in class StreamImpl
Parameters:
buf - byte buffer containing the bytes
offset - offset into the buffer
length - number of bytes to read
isEnd - if the write is at a close.
Throws:
throws - ClientDisconnectException if the connection is dropped
java.io.IOException

resetTotalBytes

public void resetTotalBytes()
Flushes the socket.


getTotalReadBytes

public long getTotalReadBytes()

getTotalWriteBytes

public long getTotalWriteBytes()

closeWrite

public void closeWrite()
                throws java.io.IOException
Closes the write half of the stream.

Overrides:
closeWrite 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