ewe.database
Class RandomAccessDatabaseStream

java.lang.Object
  extended byewe.database.RandomAccessDatabaseStream
All Implemented Interfaces:
DatabaseStream

public class RandomAccessDatabaseStream
extends Object
implements DatabaseStream


Field Summary
 int maxBufferSize
           
static boolean unsafe
           
 
Constructor Summary
RandomAccessDatabaseStream(File file, String mode)
           
RandomAccessDatabaseStream(File file, String mode, boolean ignoreInconsistentState)
           
RandomAccessDatabaseStream(RandomAccessStream stream, String mode)
           
RandomAccessDatabaseStream(RandomAccessStream stream, String mode, boolean ignoreInconsistentState)
           
 
Method Summary
 boolean atEOF(long location)
           
 boolean canWrite()
          Tests if the DatabaseStream was opened in read-write mode as opposed to read-ony mode.
 void close()
           
 void delete()
           
 void flush()
           
 int getFirstDataLocation()
          Return the location of where you can store your data.
 Time getModifiedTime()
           
 long length()
           
protected  int read(byte[] data, int offset, int length)
           
 void readAll(long location, byte[] data, int offset, int length)
          This throws an exception if all the specified bytes are not found at the specified location.
 int readIntAt(long location)
           
 void rename(String newName)
           
 void reopen()
          Reopen the stream after a temporaryClose().
 void safeWrite(long location, int data)
          A safeWrite() is one where the integer data is either stored completely at the specified location or not at all.
 void safeWrite(long loc1, int data1, long loc2, int data2)
           
 void safeWrite(long loc1, int data1, long loc2, int data2, long loc3, int data3, long loc4, int data4)
           
 boolean setDecryptor(DataProcessor decryptor)
           
 boolean setDecryptorAndEncryptor(DataProcessor decryptor, DataProcessor encryptor)
           
 boolean setModifiedTime(Time t)
           
 boolean temporaryClose()
          Close the stream temporarily.
 boolean truncateTo(long length)
          Try to truncate to a particular length.
protected  void write(byte[] data, int offset, int length)
           
 void writeAll(long location, byte[] data, int offset, int length)
           
 void writeIntAt(long location, int value)
           
 void zero(long location, int numBytes)
          This should extend the Stream if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

unsafe

public static boolean unsafe

maxBufferSize

public int maxBufferSize
Constructor Detail

RandomAccessDatabaseStream

public RandomAccessDatabaseStream(File file,
                                  String mode)
                           throws IOException

RandomAccessDatabaseStream

public RandomAccessDatabaseStream(File file,
                                  String mode,
                                  boolean ignoreInconsistentState)
                           throws IOException

RandomAccessDatabaseStream

public RandomAccessDatabaseStream(RandomAccessStream stream,
                                  String mode)
                           throws InconsistentDatabaseStateException,
                                  IOException

RandomAccessDatabaseStream

public RandomAccessDatabaseStream(RandomAccessStream stream,
                                  String mode,
                                  boolean ignoreInconsistentState)
                           throws InconsistentDatabaseStateException,
                                  IOException
Method Detail

canWrite

public boolean canWrite()
Description copied from interface: DatabaseStream
Tests if the DatabaseStream was opened in read-write mode as opposed to read-ony mode.

Specified by:
canWrite in interface DatabaseStream

temporaryClose

public boolean temporaryClose()
                       throws IOException
Description copied from interface: DatabaseStream
Close the stream temporarily. Can be opened with re-open.

Specified by:
temporaryClose in interface DatabaseStream
Returns:
true if it was actually closed.
Throws:
IOException - if an error occurs.

reopen

public void reopen()
            throws IOException
Description copied from interface: DatabaseStream
Reopen the stream after a temporaryClose(). The file position will be unspecified after this call.

Specified by:
reopen in interface DatabaseStream
Throws:
IOException - if an error occurs.

getFirstDataLocation

public int getFirstDataLocation()
Description copied from interface: DatabaseStream
Return the location of where you can store your data. This should be at a 16-byte border.

Specified by:
getFirstDataLocation in interface DatabaseStream

write

protected void write(byte[] data,
                     int offset,
                     int length)
              throws IOException
Throws:
IOException

read

protected int read(byte[] data,
                   int offset,
                   int length)
            throws IOException
Throws:
IOException

writeAll

public void writeAll(long location,
                     byte[] data,
                     int offset,
                     int length)
              throws IOException
Specified by:
writeAll in interface DatabaseStream
Throws:
IOException

readAll

public void readAll(long location,
                    byte[] data,
                    int offset,
                    int length)
             throws IOException
Description copied from interface: DatabaseStream
This throws an exception if all the specified bytes are not found at the specified location.

Specified by:
readAll in interface DatabaseStream
Throws:
IOException

zero

public void zero(long location,
                 int numBytes)
          throws IOException
Description copied from interface: DatabaseStream
This should extend the Stream if necessary.

Specified by:
zero in interface DatabaseStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface DatabaseStream
Throws:
IOException

truncateTo

public boolean truncateTo(long length)
                   throws IOException
Description copied from interface: DatabaseStream
Try to truncate to a particular length. If the truncate is not possible because of restrictions on the underlying Stream, this returns false. An IOException is only thrown if there is a serious IO error which indicates IO should be abandonded.

Specified by:
truncateTo in interface DatabaseStream
Throws:
IOException

readIntAt

public int readIntAt(long location)
              throws IOException
Specified by:
readIntAt in interface DatabaseStream
Throws:
IOException

writeIntAt

public void writeIntAt(long location,
                       int value)
                throws IOException
Specified by:
writeIntAt in interface DatabaseStream
Throws:
IOException

safeWrite

public void safeWrite(long location,
                      int data)
               throws IOException
Description copied from interface: DatabaseStream
A safeWrite() is one where the integer data is either stored completely at the specified location or not at all. If for some reason, the application should fail during the safe write (assuming that there is no problem with the file) then either the write had no effect, OR, the write would be completed the next time the file is opened.

Specified by:
safeWrite in interface DatabaseStream
Throws:
IOException

safeWrite

public void safeWrite(long loc1,
                      int data1,
                      long loc2,
                      int data2)
               throws IOException
Specified by:
safeWrite in interface DatabaseStream
Throws:
IOException

safeWrite

public void safeWrite(long loc1,
                      int data1,
                      long loc2,
                      int data2,
                      long loc3,
                      int data3,
                      long loc4,
                      int data4)
               throws IOException
Specified by:
safeWrite in interface DatabaseStream
Throws:
IOException

atEOF

public boolean atEOF(long location)
              throws IOException
Specified by:
atEOF in interface DatabaseStream
Throws:
IOException

length

public long length()
            throws IOException
Specified by:
length in interface DatabaseStream
Throws:
IOException

setDecryptor

public boolean setDecryptor(DataProcessor decryptor)
                     throws IOException
Specified by:
setDecryptor in interface DatabaseStream
Throws:
IOException

setDecryptorAndEncryptor

public boolean setDecryptorAndEncryptor(DataProcessor decryptor,
                                        DataProcessor encryptor)
                                 throws IOException
Specified by:
setDecryptorAndEncryptor in interface DatabaseStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface DatabaseStream
Throws:
IOException

delete

public void delete()
            throws IOException
Specified by:
delete in interface DatabaseStream
Throws:
IOException

rename

public void rename(String newName)
            throws IOException
Specified by:
rename in interface DatabaseStream
Throws:
IOException

getModifiedTime

public Time getModifiedTime()
Specified by:
getModifiedTime in interface DatabaseStream

setModifiedTime

public boolean setModifiedTime(Time t)
Specified by:
setModifiedTime in interface DatabaseStream