com.caucho.vfs
Class DatastoreReadStream

java.lang.Object
  extended by com.caucho.vfs.StreamImpl
      extended by com.caucho.vfs.DatastoreReadStream
All Implemented Interfaces:
LockableStream

public class DatastoreReadStream
extends StreamImpl
implements LockableStream

Stream encapsulating FileInputStream


Field Summary
 
Fields inherited from class com.caucho.vfs.StreamImpl
_nullPath, _path
 
Constructor Summary
DatastoreReadStream()
          Create a new FileReadStream.
DatastoreReadStream(DatastoreInputStream is)
          Create a new FileReadStream based on the java.io.* stream.
DatastoreReadStream(DatastoreInputStream is, DatastorePath path)
          Create a new FileReadStream based on the java.io.* stream.
 
Method Summary
 boolean canRead()
          Returns true if there's an associated file.
 void close()
          Closes the underlying stream.
 int getAvailable()
          Returns the number of bytes available for reading.
 boolean hasSkip()
          Returns true if there's an associated file.
 void init(DatastoreInputStream is)
          Initializes a VfsStream with an input/output stream pair.
 boolean lock(boolean shared, boolean block)
          Lock the shared advisory lock.
 int read(byte[] buf, int offset, int length)
          Reads bytes from the file.
 void seekStart(long offset)
          Seeks based on the start.
 long skip(long n)
          Skips bytes in the file.
 boolean unlock()
          Unlock the advisory lock.
 
Methods inherited from class com.caucho.vfs.StreamImpl
canWrite, clearWrite, closeWrite, flush, flushBuffer, flushToDisk, getAttribute, getAttributeNames, getFlushOnNewline, getNewline, getPath, getReadBuffer, getReadPosition, isClosed, isEof, readNonBlock, readTimeout, removeAttribute, seekEnd, setAttribute, setPath, setWriteEncoding, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatastoreReadStream

public DatastoreReadStream()
Create a new FileReadStream.


DatastoreReadStream

public DatastoreReadStream(DatastoreInputStream is)
Create a new FileReadStream based on the java.io.* stream.

Parameters:
is - the underlying input stream.

DatastoreReadStream

public DatastoreReadStream(DatastoreInputStream is,
                           DatastorePath path)
Create a new FileReadStream based on the java.io.* stream.

Parameters:
is - the underlying input stream.
path - the associated Path.
Method Detail

init

public void init(DatastoreInputStream is)
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.

hasSkip

public boolean hasSkip()
Returns true if there's an associated file.

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

seekStart

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

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

canRead

public boolean canRead()
Returns true if there's an associated file.

Overrides:
canRead in class StreamImpl

read

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

Overrides:
read in class StreamImpl
Parameters:
buf - a byte array receiving the data.
offset - starting index to receive data.
length - number of bytes to read.
Returns:
the number of bytes read or -1 on end of file.
Throws:
java.io.IOException

getAvailable

public int getAvailable()
                 throws java.io.IOException
Returns the number of bytes available for reading.

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

close

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

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

lock

public boolean lock(boolean shared,
                    boolean block)
Description copied from interface: LockableStream
Lock the shared advisory lock. This method will create a shared "read" lock when the shared argument is true and an exclusive "write" lock when the shared argument is false. If the block argument is false then this call will not block if the lock can't be obtained.

Specified by:
lock in interface LockableStream

unlock

public boolean unlock()
Description copied from interface: LockableStream
Unlock the advisory lock. Return true if a lock was held, false otherwise.

Specified by:
unlock in interface LockableStream