com.caucho.vfs
Class VfsStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.vfs.VfsStream
Direct Known Subclasses:
DatastoreWriteStream, FileWriteStream

public class VfsStream
extends StreamImpl

Stream encapsulating InputStream/OutputStream.


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Constructor Summary
VfsStream()
          Create an empty VfsStream.
VfsStream(java.io.InputStream is, java.io.OutputStream os)
          Create a new VfsStream based on the java.io.* stream.
VfsStream(java.io.InputStream is, java.io.OutputStream os, Path path)
           
 
Method Summary
 boolean canRead()
          Returns true if this is a read stream.
 boolean canWrite()
          Returns true if this is a writable stream.
 void close()
          Closes the stream.
 void flush()
          Flushes the write output.
 void flushToDisk()
          Flushes the write output, forcing to disk.
 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.
 long getReadPosition()
          Returns the current read position of the underlying file.
 boolean hasSkip()
          Returns true if the stream implements skip.
 void init(java.io.InputStream is, java.io.OutputStream os)
          Initializes a VfsStream with an input/output stream pair.
static ReadStream openRead(java.io.InputStream is)
          Opens a read stream based on a java.io.InputStream.
static ReadStream openRead(java.io.InputStream is, WriteStream ws)
           
static ReadWritePair openReadWrite(java.io.InputStream is, java.io.OutputStream os)
           
static WriteStream openWrite(java.io.OutputStream os)
           
 int read(byte[] buf, int offset, int length)
          Reads the next chunk from the stream.
 void setCloseChildOnClose(boolean close)
           
 void setFlushOnNewline(boolean value)
           
 void setNewline(byte[] newline)
           
 long skip(long n)
          Skips a number of bytes, returning the bytes skipped.
 void write(byte[] buf, int offset, int length, boolean isEnd)
          Writes a buffer to the underlying stream.
 
Methods inherited from class com.caucho.vfs.StreamImpl
clearWrite, closeWrite, flushBuffer, getAttribute, getAttributeNames, getPath, getReadBuffer, isClosed, isEof, readNonBlock, readTimeout, 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

VfsStream

public VfsStream()
Create an empty VfsStream.


VfsStream

public VfsStream(java.io.InputStream is,
                 java.io.OutputStream os)
Create a new VfsStream based on the java.io.* stream.


VfsStream

public VfsStream(java.io.InputStream is,
                 java.io.OutputStream os,
                 Path path)
Method Detail

init

public void init(java.io.InputStream is,
                 java.io.OutputStream os)
Initializes a VfsStream with an input/output stream pair. Before a read, the output will be flushed to avoid deadlocks.

Parameters:
is - the underlying InputStream.
os - the underlying OutputStream.

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

openReadWrite

public static ReadWritePair openReadWrite(java.io.InputStream is,
                                          java.io.OutputStream os)

openRead

public static ReadStream openRead(java.io.InputStream is)
Opens a read stream based on a java.io.InputStream.

Parameters:
is - the underlying InputStream.
Returns:
the new ReadStream

openRead

public static ReadStream openRead(java.io.InputStream is,
                                  WriteStream ws)

openWrite

public static WriteStream openWrite(java.io.OutputStream os)

canRead

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

Overrides:
canRead in class StreamImpl

read

public int read(byte[] buf,
                int offset,
                int length)
         throws java.io.IOException
Description copied from class: StreamImpl
Reads the next chunk from the stream.

Overrides:
read in class StreamImpl
Parameters:
buf - 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

hasSkip

public boolean hasSkip()
Description copied from class: StreamImpl
Returns true if the stream implements skip.

Overrides:
hasSkip in class StreamImpl

skip

public long skip(long n)
          throws java.io.IOException
Description copied from class: StreamImpl
Skips a number of bytes, returning the bytes skipped.

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

getAvailable

public int getAvailable()
                 throws java.io.IOException
Description copied from class: StreamImpl
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.

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

getReadPosition

public long getReadPosition()
Description copied from class: StreamImpl
Returns the current read position of the underlying file.

Overrides:
getReadPosition in class StreamImpl

canWrite

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

Overrides:
canWrite in class StreamImpl

getFlushOnNewline

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

Overrides:
getFlushOnNewline in class StreamImpl

setFlushOnNewline

public void setFlushOnNewline(boolean value)

write

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

Overrides:
write in class StreamImpl
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

flushToDisk

public void flushToDisk()
                 throws java.io.IOException
Description copied from class: StreamImpl
Flushes the write output, forcing to disk.

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

flush

public void flush()
           throws java.io.IOException
Description copied from class: StreamImpl
Flushes the write output.

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

setCloseChildOnClose

public void setCloseChildOnClose(boolean close)

close

public void close()
           throws java.io.IOException
Description copied from class: StreamImpl
Closes the stream.

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