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 SummaryFieldsModifier and TypeFieldDescriptionstatic final byteThe size of the header that indicates the amount of data stored in an occupied block.
- 
Constructor SummaryConstructorsConstructorDescriptionIndexedDisk(File file, IElementSerializer elementSerializer) Constructor for the Disk object
- 
Method SummaryModifier 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_BYTESThe size of the header that indicates the amount of data stored in an occupied block.- See Also:
 
 
- 
- 
Constructor Details- 
IndexedDiskConstructor for the Disk object- Parameters:
- file-
- elementSerializer-
- Throws:
- IOException
 
 
- 
- 
Method Details- 
readObjectprotected <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
 
- 
moveMoves the data stored from one position to another. The descriptor's position is updated.- Parameters:
- ded-
- newPosition-
- Throws:
- IOException
 
- 
writeWrites the given byte array to the Disk at the specified position.- Parameters:
- data-
- ded-
- Returns:
- true if we wrote successfully
- Throws:
- IOException
 
- 
writeObjectSerializes the object and write it out to the given position.TODO: make this take a ded as well. - Parameters:
- obj-
- pos-
- Throws:
- IOException
 
- 
lengthReturns the raf length.- Returns:
- the length of the file.
- Throws:
- IOException- If an I/O error occurs.
 
- 
closeCloses the raf.- Specified by:
- closein interface- AutoCloseable
- Throws:
- IOException
 
- 
resetSets the raf to empty.- Throws:
- IOException
 
- 
truncateTruncates the file to a given length.- Parameters:
- length- the new length of the file
- Throws:
- IOException
 
- 
getFilePathThis is used for debugging.- Returns:
- the file path.
 
- 
isEmptyTests 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
 
 
-