|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.deckfour.xes.nikefs2.NikeFS2BlockProvider
public class NikeFS2BlockProvider
This class implements a block provider for the NikeFS2 virtual file system. It is backed by an OS-level random-access file, which stores the actual contents of the blocks. Also, this class contains static facilities for managing the current set of open files, thereby reducing the number of concurrently open and used file handles to a sensible minimum.
Field Summary | |
---|---|
protected BitSet |
blockAllocationMap
Bit set indicating which blocks served by this provider are still free, i.e. |
protected int |
blockSize
Size (in bytes) of each block in this block provider. |
protected File |
file
Backing file for this block provider. |
protected boolean |
mapped
Flag indicating whether this block provider is using memory mapping for faster access to its contents (default and recommended is true). |
protected int |
numberOfBlocks
Number of blocks provided by this block provider. |
protected RandomAccessFile |
rafile
Random-access file wrapper, if non-mapped |
protected int |
size
Size (in bytes) of this block provider, i.e. |
Constructor Summary | |
---|---|
NikeFS2BlockProvider(File storage,
int size,
int blockSize,
boolean mapped)
Creates a new block provider. |
Method Summary | |
---|---|
NikeFS2Block |
allocateBlock()
Allocates a new block from this block provider. |
int |
blockSize()
Returns the size of blocks provided by this instance. |
void |
freeBlock(NikeFS2Block block)
De-allocates the specified block in this provider. |
int |
getBlockOffset(int blockNumber)
Returns the internal offset of the specified block in the backing file (in bytes). |
File |
getFile()
Provides direct access to the backing file. |
int |
numberOfBlocks()
Returns the number of blocks provided by this instance. |
int |
numberOfFreeBlocks()
Returns the number of non-allocated blocks in this instance. |
int |
read(int blockNumber,
int blockOffset)
Reads from the specified block. |
int |
read(int blockNumber,
int blockOffset,
byte[] buffer)
Reads from the specified block. |
int |
read(int blockNumber,
int blockOffset,
byte[] buffer,
int bufferOffset,
int length)
Reads from the specified block. |
int |
size()
Returns the size, in bytes, of this block provider in total. |
void |
write(int blockNumber,
int blockOffset,
byte[] buffer)
Writes to this block. |
void |
write(int blockNumber,
int blockOffset,
byte[] buffer,
int bufferOffset,
int length)
Writes to this block. |
void |
write(int blockNumber,
int blockOffset,
int value)
Writes to this block. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final boolean mapped
protected final File file
protected final RandomAccessFile rafile
protected final int size
protected final int blockSize
protected final int numberOfBlocks
protected final BitSet blockAllocationMap
true
, at the block's
index in this bit set, indicates that the block is free.
Blocks whose index's bit is set to false
are
currently allocated.
Constructor Detail |
---|
public NikeFS2BlockProvider(File storage, int size, int blockSize, boolean mapped) throws IOException
storage
- Backing file to store actual contents in.size
- Size of the backing file in bytes.blockSize
- Size of blocks in bytes.mapped
- Whether to use memory mapping for this block
provider (it is recommended to set this flag to true
).
IOException
Method Detail |
---|
public File getFile()
public int size()
public int numberOfBlocks()
public int numberOfFreeBlocks()
public int blockSize()
public NikeFS2Block allocateBlock()
null
, if no free blocks are
currently available.public void freeBlock(NikeFS2Block block)
block
- The block to be freed.public int getBlockOffset(int blockNumber)
blockNumber
- The internal number of the block in question.
public int read(int blockNumber, int blockOffset, byte[] buffer) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset, in bytes, within this block.buffer
- Buffer to store read data in.
IOException
public int read(int blockNumber, int blockOffset, byte[] buffer, int bufferOffset, int length) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset, in bytes, within this block.buffer
- Buffer to store read data in.bufferOffset
- Offset in the given buffer to start writing at.length
- Number of bytes to be read.
IOException
public int read(int blockNumber, int blockOffset) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset, in bytes, within this block.
IOException
public void write(int blockNumber, int blockOffset, byte[] buffer) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset within the block to commence writing at.buffer
- Buffer storing the data to be written.
IOException
public void write(int blockNumber, int blockOffset, byte[] buffer, int bufferOffset, int length) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset within the block to commence writing at.buffer
- Buffer storing the data to be written.bufferOffset
- Offset within the buffer from where to read.length
- Number of bytes to be written.
IOException
public void write(int blockNumber, int blockOffset, int value) throws IOException
blockNumber
- Internal number of the block in question.blockOffset
- Offset within the block to commence writing at.value
- Byte value to be written.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |