com.caucho.vfs
Class FileRandomAccessStream

java.lang.Object
  extended by com.caucho.vfs.RandomAccessStream
      extended by com.caucho.vfs.FileRandomAccessStream
All Implemented Interfaces:
LockableStream

public class FileRandomAccessStream
extends RandomAccessStream
implements LockableStream

Reads from a file in a random-access fashion.


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

Constructor Detail

FileRandomAccessStream

public FileRandomAccessStream(java.io.RandomAccessFile file)
Method Detail

getRandomAccessFile

public java.io.RandomAccessFile getRandomAccessFile()

getLength

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

Specified by:
getLength in class RandomAccessStream
Throws:
java.io.IOException

read

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

Specified by:
read in class RandomAccessStream
Throws:
java.io.IOException

read

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

Specified by:
read in class RandomAccessStream
Throws:
java.io.IOException

read

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

Specified by:
read in class RandomAccessStream
Throws:
java.io.IOException

write

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

Specified by:
write in class RandomAccessStream
Throws:
java.io.IOException

write

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

Specified by:
write in class RandomAccessStream
Throws:
java.io.IOException

seek

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

Specified by:
seek in class RandomAccessStream

getOutputStream

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

Specified by:
getOutputStream in class RandomAccessStream
Throws:
java.io.IOException

getInputStream

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

Specified by:
getInputStream in class RandomAccessStream
Throws:
java.io.IOException

read

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

Specified by:
read in class RandomAccessStream
Throws:
java.io.IOException

write

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

Specified by:
write in class RandomAccessStream
Throws:
java.io.IOException

getFilePointer

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

Specified by:
getFilePointer in class RandomAccessStream
Throws:
java.io.IOException

closeImpl

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

Overrides:
closeImpl in class RandomAccessStream
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
Overrides:
lock in class RandomAccessStream

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
Overrides:
unlock in class RandomAccessStream

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object