ewe.database
Interface DatabaseStream

All Known Implementing Classes:
RandomAccessDatabaseStream

public interface DatabaseStream

This is not part of the Ewe Simple Database specification. This is used for an actual implementation of Simple Database, specifically by RecordFile.


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()
           
 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 location1, int data1, long location2, int data2)
           
 void safeWrite(long location1, int data1, long location2, int data2, long location3, int data3, long location4, 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.
 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.
 

Method Detail

getFirstDataLocation

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


safeWrite

public void safeWrite(long location,
                      int data)
               throws IOException
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.

Throws:
IOException

safeWrite

public void safeWrite(long location1,
                      int data1,
                      long location2,
                      int data2)
               throws IOException
Throws:
IOException

safeWrite

public void safeWrite(long location1,
                      int data1,
                      long location2,
                      int data2,
                      long location3,
                      int data3,
                      long location4,
                      int data4)
               throws IOException
Throws:
IOException

readIntAt

public int readIntAt(long location)
              throws IOException
Throws:
IOException

writeIntAt

public void writeIntAt(long location,
                       int value)
                throws IOException
Throws:
IOException

writeAll

public void writeAll(long location,
                     byte[] data,
                     int offset,
                     int length)
              throws IOException
Throws:
IOException

readAll

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

Throws:
IOException

zero

public void zero(long location,
                 int numBytes)
          throws IOException
This should extend the Stream if necessary.

Throws:
IOException

truncateTo

public boolean truncateTo(long length)
                   throws IOException
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.

Throws:
IOException

setDecryptor

public boolean setDecryptor(DataProcessor decryptor)
                     throws IOException
Throws:
IOException

setDecryptorAndEncryptor

public boolean setDecryptorAndEncryptor(DataProcessor decryptor,
                                        DataProcessor encryptor)
                                 throws IOException
Throws:
IOException

atEOF

public boolean atEOF(long location)
              throws IOException
Throws:
IOException

length

public long length()
            throws IOException
Throws:
IOException

flush

public void flush()
           throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException

delete

public void delete()
            throws IOException
Throws:
IOException

rename

public void rename(String newName)
            throws IOException
Throws:
IOException

getModifiedTime

public Time getModifiedTime()
                     throws IOException
Throws:
IOException

setModifiedTime

public boolean setModifiedTime(Time t)
                        throws IOException
Throws:
IOException

temporaryClose

public boolean temporaryClose()
                       throws IOException
Close the stream temporarily. Can be opened with re-open.

Returns:
true if it was actually closed.
Throws:
IOException - if an error occurs.

reopen

public void reopen()
            throws IOException
Reopen the stream after a temporaryClose(). The file position will be unspecified after this call.

Throws:
IOException - if an error occurs.

canWrite

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