public class BlockDisk
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected IElementSerializer |
elementSerializer
The serializer.
|
static byte |
HEADER_SIZE_BYTES
The size of the header that indicates the amount of data stored in an occupied block.
|
Constructor and Description |
---|
BlockDisk(java.io.File file,
IElementSerializer elementSerializer)
Constructor for the Disk object
|
BlockDisk(java.io.File file,
int blockSizeBytes)
Creates the file and set the block size in bytes.
|
Modifier and Type | Method and Description |
---|---|
protected int |
calculateByteOffsetForBlock(int block)
Calcuates the file offset for a particular block.
|
protected int |
calculateTheNumberOfBlocksNeeded(byte[] data)
The number of blocks needed.
|
protected void |
close()
Closes the raf.
|
protected void |
freeBlocks(int[] blocksToFree)
Add these blocks to the emptyBlock list.
|
protected long |
getAveragePutSizeBytes() |
protected byte[][] |
getBlockChunks(byte[] complete,
int numBlocksNeeded)
Return the amount to put in each block.
|
protected int |
getBlockSizeBytes() |
protected int |
getEmptyBlocks() |
protected java.lang.String |
getFilePath()
This is used for debugging.
|
protected int |
getNumberOfBlocks() |
protected long |
length()
Returns the raf length.
|
protected java.io.Serializable |
read(int[] blockNumbers)
Reads an object that is located in the specified blocks.
|
java.lang.String |
toString()
For debugging only.
|
protected int[] |
write(java.io.Serializable object)
This writes an object to disk and returns the blocks it was stored in.
|
public static final byte HEADER_SIZE_BYTES
protected IElementSerializer elementSerializer
public BlockDisk(java.io.File file, IElementSerializer elementSerializer) throws java.io.FileNotFoundException
file
- elementSerializer
- java.io.FileNotFoundException
public BlockDisk(java.io.File file, int blockSizeBytes) throws java.io.FileNotFoundException
file
- blockSizeBytes
- java.io.FileNotFoundException
protected int[] write(java.io.Serializable object) throws java.io.IOException
The program flow is as follows:
object
- java.io.IOException
protected byte[][] getBlockChunks(byte[] complete, int numBlocksNeeded)
complete
- numBlocksNeeded
- protected java.io.Serializable read(int[] blockNumbers) throws java.io.IOException, java.lang.ClassNotFoundException
blockNumbers
- java.io.IOException
java.lang.ClassNotFoundException
protected void freeBlocks(int[] blocksToFree)
blocksToFree
- protected int calculateByteOffsetForBlock(int block)
block
- protected int calculateTheNumberOfBlocksNeeded(byte[] data)
data
- protected long length() throws java.io.IOException
java.io.IOException
protected void close() throws java.io.IOException
java.io.IOException
protected int getNumberOfBlocks()
protected int getBlockSizeBytes()
protected long getAveragePutSizeBytes()
protected int getEmptyBlocks()
public java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.String getFilePath()
Copyright © 2002-2013 Apache Software Foundation. All Rights Reserved.