com.caucho.vfs
Class RandomAccessStream

java.lang.Object
  extended by com.caucho.vfs.RandomAccessStream
All Implemented Interfaces:
LockableStream
Direct Known Subclasses:
DatastoreRandomAccessStream, FileRandomAccessStream, JniMemoryMappedFile, JniRandomAccessFile, SpyRandomAccessStream

public abstract class RandomAccessStream
extends java.lang.Object
implements LockableStream

Reads from a file in a random-access fashion.


Constructor Summary
RandomAccessStream()
           
 
Method Summary
 boolean allocate()
           
 void close()
          Closes the stream.
 void closeImpl()
          Closes the stream.
 void free()
           
abstract  long getFilePointer()
          Returns the current position of the file pointer.
abstract  java.io.InputStream getInputStream()
          Returns an InputStream for this stream.
abstract  long getLength()
          Returns the length.
abstract  java.io.OutputStream getOutputStream()
          Returns an OutputStream for this stream.
 long getUseCount()
           
 boolean isOpen()
           
 boolean lock(boolean shared, boolean block)
          Lock the shared advisory lock.
abstract  int read()
          Read a byte from the file, advancing the pointer.
abstract  int read(byte[] buffer, int offset, int length)
          Reads a block starting from the current file pointer.
abstract  int read(char[] buffer, int offset, int length)
          Reads a block starting from the current file pointer.
abstract  int read(long fileOffset, byte[] buffer, int offset, int length)
          Reads a block from a given location.
abstract  boolean seek(long position)
          Seeks to the given position in the file.
 boolean unlock()
          Unlock the advisory lock.
abstract  void write(byte[] buffer, int offset, int length)
          Writes a block starting from the current file pointer.
abstract  void write(int b)
          Write a byte to the file, advancing the pointer.
abstract  void write(long fileOffset, byte[] buffer, int offset, int length)
          Writes a block to a given location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomAccessStream

public RandomAccessStream()
Method Detail

getLength

public abstract long getLength()
                        throws java.io.IOException
Returns the length.

Throws:
java.io.IOException

read

public abstract int read(byte[] buffer,
                         int offset,
                         int length)
                  throws java.io.IOException
Reads a block starting from the current file pointer.

Throws:
java.io.IOException

read

public abstract int read(char[] buffer,
                         int offset,
                         int length)
                  throws java.io.IOException
Reads a block starting from the current file pointer.

Throws:
java.io.IOException

read

public abstract int read(long fileOffset,
                         byte[] buffer,
                         int offset,
                         int length)
                  throws java.io.IOException
Reads a block from a given location.

Throws:
java.io.IOException

write

public abstract void write(byte[] buffer,
                           int offset,
                           int length)
                    throws java.io.IOException
Writes a block starting from the current file pointer.

Throws:
java.io.IOException

write

public abstract void write(long fileOffset,
                           byte[] buffer,
                           int offset,
                           int length)
                    throws java.io.IOException
Writes a block to a given location.

Throws:
java.io.IOException

seek

public abstract boolean seek(long position)
Seeks to the given position in the file.


getOutputStream

public abstract java.io.OutputStream getOutputStream()
                                              throws java.io.IOException
Returns an OutputStream for this stream.

Throws:
java.io.IOException

getInputStream

public abstract java.io.InputStream getInputStream()
                                            throws java.io.IOException
Returns an InputStream for this stream.

Throws:
java.io.IOException

read

public abstract int read()
                  throws java.io.IOException
Read a byte from the file, advancing the pointer.

Throws:
java.io.IOException

write

public abstract void write(int b)
                    throws java.io.IOException
Write a byte to the file, advancing the pointer.

Throws:
java.io.IOException

getFilePointer

public abstract long getFilePointer()
                             throws java.io.IOException
Returns the current position of the file pointer.

Throws:
java.io.IOException

isOpen

public final boolean isOpen()

getUseCount

public final long getUseCount()

allocate

public final boolean allocate()

free

public final void free()

close

public final void close()
Closes the stream.


closeImpl

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

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