Class IndexedDisk
java.lang.Object
org.apache.commons.jcs3.auxiliary.disk.indexed.IndexedDisk
- All Implemented Interfaces:
AutoCloseable
Provides thread safe access to the underlying random access file.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteThe size of the header that indicates the amount of data stored in an occupied block. -
Constructor Summary
ConstructorsConstructorDescriptionIndexedDisk(File file, IElementSerializer elementSerializer) Constructor for the Disk object -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the raf.protected StringThis is used for debugging.protected booleanisEmpty()Tests if the length is 0.protected longlength()Returns the raf length.protected voidmove(IndexedDiskElementDescriptor ded, long newPosition) Moves the data stored from one position to another.protected <T> TThis reads an object from the given starting position on the file.protected voidreset()Sets the raf to empty.protected voidtruncate(long length) Truncates the file to a given length.protected booleanwrite(IndexedDiskElementDescriptor ded, byte[] data) Writes the given byte array to the Disk at the specified position.protected <T> voidwriteObject(T obj, long pos) Serializes the object and write it out to the given position.
-
Field Details
-
HEADER_SIZE_BYTES
The size of the header that indicates the amount of data stored in an occupied block.- See Also:
-
-
Constructor Details
-
IndexedDisk
Constructor for the Disk object- Parameters:
file-elementSerializer-- Throws:
IOException
-
-
Method Details
-
readObject
protected <T> T readObject(IndexedDiskElementDescriptor ded) throws IOException, ClassNotFoundException This reads an object from the given starting position on the file.The first four bytes of the record should tell us how long it is. The data is read into a byte array and then an object is constructed from the byte array.
- Parameters:
ded-- Returns:
- Serializable
- Throws:
IOExceptionClassNotFoundException
-
move
Moves the data stored from one position to another. The descriptor's position is updated.- Parameters:
ded-newPosition-- Throws:
IOException
-
write
Writes the given byte array to the Disk at the specified position.- Parameters:
data-ded-- Returns:
- true if we wrote successfully
- Throws:
IOException
-
writeObject
Serializes the object and write it out to the given position.TODO: make this take a ded as well.
- Parameters:
obj-pos-- Throws:
IOException
-
length
Returns the raf length.- Returns:
- the length of the file.
- Throws:
IOException- If an I/O error occurs.
-
close
Closes the raf.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
reset
Sets the raf to empty.- Throws:
IOException
-
truncate
Truncates the file to a given length.- Parameters:
length- the new length of the file- Throws:
IOException
-
getFilePath
This is used for debugging.- Returns:
- the file path.
-
isEmpty
Tests if the length is 0.- Returns:
- true if the if the length is 0.
- Throws:
IOException- If an I/O error occurs.- Since:
- 3.1
-