|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gillius.realdb.io.RandomAccessBlockFile
public class RandomAccessBlockFile
RandomAccessBlockFile implements the BlockFile interface through a given RandomAccessFile, which should be opened in "rwd" or "rws" mode as appropriate. If the JVM and operating system do not implement these modes properly, it is possible that RandomAccessBlockFile cannot completely make the write behavior guarantees. On Windows XP and Linux using the Sun J2SE 1.6, this does appear to work based on my research.
An instance of this class cannot be shared between threads. TODO: this class may need an "offset" attribute to fully guarantee the writeBlock behavior
Constructor Summary | |
---|---|
RandomAccessBlockFile(java.io.RandomAccessFile file,
int blockSize)
Constructs a new RandomAccessBlockFile to work with the given file and block size. |
|
RandomAccessBlockFile(java.io.RandomAccessFile file,
int blockSize,
int numBlocks)
Constructs a new RandomAccessBlockFile to work with the given parameters. |
Method Summary | |
---|---|
void |
close()
|
int |
getBlockSize()
Returns the size of a block, in bytes. |
int |
getSize()
Returns the size of the file, in blocks. |
void |
readBlock(int num,
byte[] data)
Read a block of data into the given buffer, which is of the size returned by BlockFile.getBlockSize() . |
int |
readBlocks(int startBlock,
byte[] data)
Reads one or more blocks from the file into the given buffer. |
void |
writeBlock(int num,
byte[] data)
Write a block of data from the given buffer, which is of the size returned by BlockFile.getBlockSize() . |
int |
writeBlocks(int startBlock,
byte[] data)
Works identically to BlockFile.writeBlocks(int, byte[], int, int) with start=0 and
len=data.length. |
int |
writeBlocks(int startBlock,
byte[] data,
int start,
int len)
Write multiple blocks of data from the given buffer, which is of any size that will fit within the file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RandomAccessBlockFile(java.io.RandomAccessFile file, int blockSize) throws java.io.IOException
java.io.IOException
public RandomAccessBlockFile(java.io.RandomAccessFile file, int blockSize, int numBlocks) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public int getSize()
BlockFile
getSize
in interface BlockFile
public void close() throws java.io.IOException
close
in interface java.io.Closeable
java.io.IOException
public int getBlockSize()
BlockFile
getBlockSize
in interface BlockFile
public void readBlock(int num, byte[] data) throws java.io.IOException
BlockFile
BlockFile.getBlockSize()
.
readBlock
in interface BlockFile
java.io.IOException
public int readBlocks(int startBlock, byte[] data) throws java.io.IOException
BlockFile
readBlocks
in interface BlockFile
startBlock
- starting block address, from 0 to BlockFile.getSize()
- 1data
- non-null data buffer that is fully populated
java.io.IOException
- if an error occurs reading the data
java.io.EOFException
- if there are not enough blocks to fill the bufferpublic void writeBlock(int num, byte[] data) throws java.io.IOException
BlockFile
BlockFile.getBlockSize()
. When this method suceeds, the block has been safely committed to the
disk. If it fails, then the block will have undefined content.
writeBlock
in interface BlockFile
java.io.IOException
public int writeBlocks(int startBlock, byte[] data) throws java.io.IOException
BlockFile
BlockFile.writeBlocks(int, byte[], int, int)
with start=0 and
len=data.length.
writeBlocks
in interface BlockFile
startBlock
- starting block address, from 0 to BlockFile.getSize()
- 1data
- non-null data block that is not too large (see main comment)
java.io.IOException
- if an error occurs while writing the data
java.io.EOFException
- if there are not enough blocks to writepublic int writeBlocks(int startBlock, byte[] data, int start, int len) throws java.io.IOException
BlockFile
BlockFile.getSize()
- startBlock) * BlockFile.getBlockSize()
is
greater than the length of data. If the size of data is not an exact multiple of the block
size, extra 0 bytes are padded at the end of the block. When this method suceeds, the block
has been safely committed to the disk. If it fails, then all of the affected blocks have an
undefined content.
The primary purpose of this method is for performance, when writing a larger logical block
than the minimum physical block size supported, when it is acceptable to entirely commit or
entirely lose the logical block in one operation.
writeBlocks
in interface BlockFile
startBlock
- starting block address, from 0 to BlockFile.getSize()
- 1data
- non-null data block that is not too large (see main comment)
java.io.IOException
- if an error occurs while writing the data
java.io.EOFException
- if there are not enough blocks to write
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |