com.caucho.vfs
Class StreamImpl

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
Direct Known Subclasses:
BinaryBuilderStream, ContentLengthStream, Crc64Stream, DatagramStream, DatastoreReadStream, EnvironmentStream, FileReadStream, HttpStreamWrapper, Jar.ZipStreamImpl, JniFileStream, JniStream, MemoryPath.MemoryStream, MemoryStream, MultipartStream, PipeStream, RawInputStream, ReaderStream, ReaderWriterStream, RotateStream, SocketChannelStream, SocketStream, StderrStream, StdoutStream, StreamFilter, StringReader, StringStream, StringWriter, TempCharStream, TempReadStream, TempStream, TimestampFilter, VfsStream, WriterStreamImpl

public class StreamImpl
extends java.lang.Object

This is the service provider's interface for a stream supported by the VFS.


Field Summary
protected static NullPath _nullPath
           
protected  Path _path
           
 
Constructor Summary
StreamImpl()
           
 
Method Summary
 boolean canRead()
          Returns true if this is a read stream.
 boolean canWrite()
          Returns true if this is a writable stream.
 void clearWrite()
          Clears any buffered values in the write.
 void close()
          Closes the stream.
 void closeWrite()
          Closes the write half of the stream.
 void flush()
          Flushes the write output.
 void flushBuffer()
          Flushes buffered writes.
 void flushToDisk()
          Flushes the write output, forcing to disk.
 java.lang.Object getAttribute(java.lang.String name)
          Returns a stream attribute.
 java.util.Iterator<java.lang.String> getAttributeNames()
          Returns an iterator of the attribute names.
 int getAvailable()
          Returns the number of bytes available without blocking.
 boolean getFlushOnNewline()
          Returns true if the buffer should be flushed on every newline.
 byte[] getNewline()
          Returns the stream's natural newline character.
 Path getPath()
          Returns the Path associated with the stream.
 byte[] getReadBuffer()
          Returns the read buffer.
 long getReadPosition()
          Returns the current read position of the underlying file.
 boolean hasSkip()
          Returns true if the stream implements skip.
 boolean isClosed()
          Returns true if the stream is closed.
 boolean isEof()
           
 int read(byte[] buffer, int offset, int length)
          Reads the next chunk from the stream.
 int readNonBlock(byte[] buffer, int offset, int length)
          Reads the next chunk from the stream in non-blocking mode.
 int readTimeout(byte[] buffer, int offset, int length, long timeout)
          Reads the next chunk from the stream in non-blocking mode.
 void removeAttribute(java.lang.String name)
          Removes a stream attribute.
 void seekEnd(long offset)
          Seeks based on the end.
 void seekStart(long offset)
          Seeks based on the start.
 void setAttribute(java.lang.String name, java.lang.Object value)
          Sets a stream attribute.
 void setPath(Path path)
          Sets the Path associated with the stream.
 void setWriteEncoding(java.lang.String encoding)
          Sets the write encoding.
 long skip(long n)
          Skips a number of bytes, returning the bytes skipped.
 void write(byte[] buffer, int offset, int length, boolean isEnd)
          Writes a buffer to the underlying stream.
 boolean write(byte[] buf1, int off1, int len1, byte[] buf2, int off2, int len2, boolean isEnd)
          Writes a pair of buffer to the underlying stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_nullPath

protected static NullPath _nullPath

_path

protected Path _path
Constructor Detail

StreamImpl

public StreamImpl()
Method Detail

getNewline

public byte[] getNewline()
Returns the stream's natural newline character.


hasSkip

public boolean hasSkip()
Returns true if the stream implements skip.


skip

public long skip(long n)
          throws java.io.IOException
Skips a number of bytes, returning the bytes skipped.

Parameters:
n - the number of types to skip.
Returns:
the actual bytes skipped.
Throws:
java.io.IOException

canRead

public boolean canRead()
Returns true if this is a read stream.


getReadBuffer

public byte[] getReadBuffer()
Returns the read buffer.


read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads the next chunk from the stream.

Parameters:
buffer - byte array receiving the data.
offset - starting offset into the array.
length - number of bytes to read.
Returns:
the number of bytes read or -1 on end of file.
Throws:
java.io.IOException

readNonBlock

public int readNonBlock(byte[] buffer,
                        int offset,
                        int length)
                 throws java.io.IOException
Reads the next chunk from the stream in non-blocking mode.

Parameters:
buffer - byte array receiving the data.
offset - starting offset into the array.
length - number of bytes to read.
Returns:
the number of bytes read, -1 on end of file, or 0 on timeout.
Throws:
java.io.IOException

readTimeout

public int readTimeout(byte[] buffer,
                       int offset,
                       int length,
                       long timeout)
                throws java.io.IOException
Reads the next chunk from the stream in non-blocking mode.

Parameters:
buffer - byte array receiving the data.
offset - starting offset into the array.
length - number of bytes to read.
Returns:
the number of bytes read, -1 on end of file, or 0 on timeout.
Throws:
java.io.IOException

getAvailable

public int getAvailable()
                 throws java.io.IOException
Returns the number of bytes available without blocking. Depending on the stream, this may return less than the actual bytes, but will always return a number > 0 if there is any data available.

Throws:
java.io.IOException

isEof

public boolean isEof()
              throws java.io.IOException
Throws:
java.io.IOException

getReadPosition

public long getReadPosition()
Returns the current read position of the underlying file.


canWrite

public boolean canWrite()
Returns true if this is a writable stream.


getFlushOnNewline

public boolean getFlushOnNewline()
Returns true if the buffer should be flushed on every newline. This is typically only true for error streams like stderr:.


setWriteEncoding

public void setWriteEncoding(java.lang.String encoding)
Sets the write encoding.


write

public void write(byte[] buffer,
                  int offset,
                  int length,
                  boolean isEnd)
           throws java.io.IOException
Writes a buffer to the underlying stream.

Parameters:
buffer - the byte array to write.
offset - the offset into the byte array.
length - the number of bytes to write.
isEnd - true when the write is flushing a close.
Throws:
java.io.IOException

write

public boolean write(byte[] buf1,
                     int off1,
                     int len1,
                     byte[] buf2,
                     int off2,
                     int len2,
                     boolean isEnd)
              throws java.io.IOException
Writes a pair of buffer to the underlying stream.

Parameters:
buf1 - the byte array to write.
off1 - the offset into the byte array.
len1 - the number of bytes to write.
buf2 - the byte array to write.
off2 - the offset into the byte array.
len2 - the number of bytes to write.
isEnd - true when the write is flushing a close.
Throws:
java.io.IOException

clearWrite

public void clearWrite()
Clears any buffered values in the write.


seekStart

public void seekStart(long offset)
               throws java.io.IOException
Seeks based on the start.

Throws:
java.io.IOException

seekEnd

public void seekEnd(long offset)
             throws java.io.IOException
Seeks based on the end.

Throws:
java.io.IOException

flushBuffer

public void flushBuffer()
                 throws java.io.IOException
Flushes buffered writes.

Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Flushes the write output.

Throws:
java.io.IOException

flushToDisk

public void flushToDisk()
                 throws java.io.IOException
Flushes the write output, forcing to disk.

Throws:
java.io.IOException

getPath

public Path getPath()
Returns the Path associated with the stream.


setPath

public void setPath(Path path)
Sets the Path associated with the stream.


getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws java.io.IOException
Returns a stream attribute.

Parameters:
name - the attribute name.
Returns:
the attribute value.
Throws:
java.io.IOException

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
                  throws java.io.IOException
Sets a stream attribute.

Parameters:
name - the attribute name.
value - the attribute value.
Throws:
java.io.IOException

removeAttribute

public void removeAttribute(java.lang.String name)
                     throws java.io.IOException
Removes a stream attribute.

Parameters:
name - the attribute name.
Throws:
java.io.IOException

getAttributeNames

public java.util.Iterator<java.lang.String> getAttributeNames()
                                                       throws java.io.IOException
Returns an iterator of the attribute names.

Throws:
java.io.IOException

closeWrite

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

Throws:
java.io.IOException

isClosed

public boolean isClosed()
Returns true if the stream is closed.


close

public void close()
           throws java.io.IOException
Closes the stream.

Throws:
java.io.IOException