com.objectwave.utility
Class CachedRandomAccessFile

java.lang.Object
  |
  +--com.objectwave.utility.BufferedRandomAccessFile
        |
        +--com.objectwave.utility.CachedRandomAccessFile
All Implemented Interfaces:
java.io.DataInput, java.io.DataOutput

public class CachedRandomAccessFile
extends BufferedRandomAccessFile

Extension fo the RandomAccessFile to cache the file until flush() is called. Usable with the com.objectwave.persist.FileBroker . Publically identical to java.io.RandomAccessFile , except for the constuctor, flush() , and readFile() .

Note: This class is not threadsafe.

Version:
$Id: CachedRandomAccessFile.java,v 2.1 2002/07/31 15:55:23 dave_hoag Exp $
Author:
Steven Sinclair
See Also:
RandomAccessFile

Nested Class Summary
protected  class CachedRandomAccessFile.FileBlock
           
static class CachedRandomAccessFile.Test
          Description of the Class
 
Nested classes inherited from class com.objectwave.utility.BufferedRandomAccessFile
BufferedRandomAccessFile.FileBufferStruct, BufferedRandomAccessFile.Test
 
Field Summary
 
Fields inherited from class com.objectwave.utility.BufferedRandomAccessFile
altBuf, currBuf
 
Constructor Summary
CachedRandomAccessFile(java.io.File file, java.lang.String mode, int blockSize, boolean fullCache)
          Constructor for the CachedRandomAccessFile object
 
Method Summary
 void flush()
          Description of the Method
protected  CachedRandomAccessFile.FileBlock getBlock(long position)
          Gets the Block attribute of the CachedRandomAccessFile object
 long getFilePointer()
          Gets the FilePointer attribute of the CachedRandomAccessFile object
 java.io.Reader getReader()
          Gets the Reader attribute of the CachedRandomAccessFile object
 java.io.Writer getWriter()
          Gets the Writer attribute of the CachedRandomAccessFile object
 long length()
          Description of the Method
static void main(java.lang.String[] args)
          The main program for the CachedRandomAccessFile class
 int read()
          Description of the Method
 int read(byte[] b)
          Description of the Method
 int read(byte[] b, int pos, int len)
          Description of the Method
 void readFile()
          Read any unloaded blocks into memory.
 void seek(long pos)
          Description of the Method
 void setLength(long newLength)
          Sets the Length attribute of the CachedRandomAccessFile object
 int skipBytes(int n)
          Description of the Method
 long skipBytes(long n)
          Description of the Method
 void write(byte[] b)
          Description of the Method
 void write(byte[] b, int pos, int len)
          Description of the Method
 void write(int b)
          Description of the Method
 
Methods inherited from class com.objectwave.utility.BufferedRandomAccessFile
close, commitBuffer, fillBuffer, getFD, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, syncBuffer, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachedRandomAccessFile

public CachedRandomAccessFile(java.io.File file,
                              java.lang.String mode,
                              int blockSize,
                              boolean fullCache)
                       throws java.io.IOException
Constructor for the CachedRandomAccessFile object

Parameters:
file - Description of Parameter
mode - Description of Parameter
blockSize - Description of Parameter
fullCache - Description of Parameter
Throws:
java.io.IOException - Description of Exception
Method Detail

setLength

public void setLength(long newLength)
               throws java.io.IOException
Sets the Length attribute of the CachedRandomAccessFile object

Overrides:
setLength in class BufferedRandomAccessFile
Parameters:
newLength - The new Length value
Throws:
java.io.IOException - Description of Exception

getReader

public java.io.Reader getReader()
Gets the Reader attribute of the CachedRandomAccessFile object

Overrides:
getReader in class BufferedRandomAccessFile
Returns:
The Reader value

getWriter

public java.io.Writer getWriter()
Gets the Writer attribute of the CachedRandomAccessFile object

Overrides:
getWriter in class BufferedRandomAccessFile
Returns:
The Writer value

getFilePointer

public long getFilePointer()
Gets the FilePointer attribute of the CachedRandomAccessFile object

Overrides:
getFilePointer in class BufferedRandomAccessFile
Returns:
The FilePointer value

length

public long length()
Description of the Method

Overrides:
length in class BufferedRandomAccessFile
Returns:
Description of the Returned Value

read

public int read()
         throws java.io.IOException
Description of the Method

Overrides:
read in class BufferedRandomAccessFile
Returns:
Description of the Returned Value
Throws:
java.io.IOException - Description of Exception

read

public int read(byte[] b)
         throws java.io.IOException
Description of the Method

Overrides:
read in class BufferedRandomAccessFile
Parameters:
b - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.io.IOException - Description of Exception

read

public int read(byte[] b,
                int pos,
                int len)
         throws java.io.IOException
Description of the Method

Overrides:
read in class BufferedRandomAccessFile
Parameters:
b - Description of Parameter
pos - Description of Parameter
len - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.io.IOException - Description of Exception

seek

public void seek(long pos)
          throws java.io.IOException
Description of the Method

Overrides:
seek in class BufferedRandomAccessFile
Parameters:
pos - Description of Parameter
Throws:
java.io.IOException - Description of Exception

skipBytes

public int skipBytes(int n)
              throws java.io.IOException
Description of the Method

Specified by:
skipBytes in interface java.io.DataInput
Overrides:
skipBytes in class BufferedRandomAccessFile
Parameters:
n - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.io.IOException - Description of Exception

skipBytes

public long skipBytes(long n)
               throws java.io.IOException
Description of the Method

Overrides:
skipBytes in class BufferedRandomAccessFile
Parameters:
n - Description of Parameter
Returns:
Description of the Returned Value
Throws:
java.io.IOException - Description of Exception

write

public void write(byte[] b)
           throws java.io.IOException
Description of the Method

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class BufferedRandomAccessFile
Parameters:
b - Description of Parameter
Throws:
java.io.IOException - Description of Exception

write

public void write(byte[] b,
                  int pos,
                  int len)
           throws java.io.IOException
Description of the Method

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class BufferedRandomAccessFile
Parameters:
b - Description of Parameter
pos - Description of Parameter
len - Description of Parameter
Throws:
java.io.IOException - Description of Exception

write

public void write(int b)
           throws java.io.IOException
Description of the Method

Specified by:
write in interface java.io.DataOutput
Overrides:
write in class BufferedRandomAccessFile
Parameters:
b - Description of Parameter
Throws:
java.io.IOException - Description of Exception

readFile

public void readFile()
              throws java.io.IOException
Read any unloaded blocks into memory.

Throws:
java.io.IOException - Description of Exception

flush

public void flush()
           throws java.io.IOException
Description of the Method

Overrides:
flush in class BufferedRandomAccessFile
Throws:
java.io.IOException - Description of Exception

getBlock

protected CachedRandomAccessFile.FileBlock getBlock(long position)
Gets the Block attribute of the CachedRandomAccessFile object

Parameters:
position - Description of Parameter
Returns:
The Block value

main

public static void main(java.lang.String[] args)
The main program for the CachedRandomAccessFile class

Parameters:
args - The command line arguments