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 byte
The 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 TypeMethodDescriptionvoid
close()
Closes the raf.protected String
This is used for debugging.protected boolean
isEmpty()
Tests if the length is 0.protected long
length()
Returns the raf length.protected void
move
(IndexedDiskElementDescriptor ded, long newPosition) Moves the data stored from one position to another.protected <T> T
This reads an object from the given starting position on the file.protected void
reset()
Sets the raf to empty.protected void
truncate
(long length) Truncates the file to a given length.protected boolean
write
(IndexedDiskElementDescriptor ded, byte[] data) Writes the given byte array to the Disk at the specified position.protected <T> void
writeObject
(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:
IOException
ClassNotFoundException
-
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:
close
in 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
-