public class RandomAccessStorageModule extends Object implements IStorageModule
RandomAccessFile,
which will immediately write all changes in the data to hard-disk.
This class is not thread-safe.
RandomAccessFile| Modifier and Type | Field and Description |
|---|---|
protected long |
sizeInBlocks
The size of the medium in blocks.
|
VIRTUAL_BLOCK_SIZE| Constructor and Description |
|---|
RandomAccessStorageModule(long sizeInBlocks,
File file)
Creates a new
RandomAccessStorageModule backed by the specified file. |
| Modifier and Type | Method and Description |
|---|---|
int |
checkBounds(long logicalBlockAddress,
int transferLengthInBlocks)
This method can be used for checking if a (series of) I/O operations will result in an
IOException due to
trying to access blocks outside the medium's boundaries. |
void |
close()
Closes the backing
RandomAccessFile. |
long |
getSizeInBlocks()
Returns the storage space size in bytes divided by the block size in bytes (rounded down).
|
static IStorageModule |
open(File file,
long storageLength,
boolean create,
Class<? extends IStorageModule> kind)
This is the build method for creating instances of
RandomAccessStorageModule. |
void |
read(byte[] bytes,
long storageIndex)
Copies bytes from storage to the passed byte array.
|
static boolean |
recursiveDelete(File pFile)
Deleting a storage recursive.
|
void |
write(byte[] bytes,
long storageIndex)
Saves part of the passed byte array's content.
|
protected final long sizeInBlocks
IStorageModule.VIRTUAL_BLOCK_SIZEpublic RandomAccessStorageModule(long sizeInBlocks,
File file)
throws FileNotFoundException
RandomAccessStorageModule backed by the specified file. If no such file exists, a
FileNotFoundException will be thrown.sizeInBlocks - blocksize for this modulefile - the path to the file serving as storage mediumFileNotFoundException - if the specified file does not existpublic void read(byte[] bytes,
long storageIndex)
throws IOException
read in interface IStorageModulebytes - the array into which the data will be copied will be filled with data from storagestorageIndex - the position of the first byte to be copiedIOExceptionpublic void write(byte[] bytes,
long storageIndex)
throws IOException
write in interface IStorageModulebytes - the source of the data to be storedstorageIndex - byte offset in the storage areaIOExceptionpublic final long getSizeInBlocks()
getSizeInBlocks in interface IStorageModulepublic final int checkBounds(long logicalBlockAddress,
int transferLengthInBlocks)
IOException due to
trying to access blocks outside the medium's boundaries.
The SCSI standard requires checking for these boundary violations right after receiving a read or write command, so that an appropriate error message can be returned to the initiator. Therefore this method must be called prior to each read or write sequence.
The values returned by this method and their meaning with regard to the interval [0, IStorageModule.getSizeInBlocks() -
1] are shown in the following table:
| Return Value | Meaning |
|---|---|
| 0 | no boundaries are violated |
| 1 | the logicalBlockAddress parameter lies outside of the interval |
| 2 | the interval [logicalBlockAddress, logicalBlockAddress + transferLengthInBlocks] lies outside of the interval, or transferLengthInBlocks is negative |
Note that the parameters of this method are referring to blocks, not to byte indices.
checkBounds in interface IStorageModulelogicalBlockAddress - the index of the first block of data to be read or writtentransferLengthInBlocks - the total number of consecutive blocks about to be read or writtenpublic final void close()
throws IOException
RandomAccessFile.close in interface IStorageModuleIOException - if an I/O Error occurspublic static final IStorageModule open(File file, long storageLength, boolean create, Class<? extends IStorageModule> kind) throws IOException
RandomAccessStorageModule. If there is no file to be
found at the specified filePath, then a FileNotFoundException will be thrown.file - a path leading to the file serving as storage mediumstorageLength - length of storage (if not already existing)create - should the storage be createdRandomAccessStorageModuleIOExceptionpublic static boolean recursiveDelete(File pFile)
pFile - which should be deleted included descendantsCopyright © 2013 University of Konstanz, Distributed Systems Group. All Rights Reserved.