public class IndexedDisk extends Object implements AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
static byte |
HEADER_SIZE_BYTES
The size of the header that indicates the amount of data stored in an occupied block.
|
| Constructor and Description |
|---|
IndexedDisk(File file,
IElementSerializer elementSerializer)
Constructor for the Disk object
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the raf.
|
protected String |
getFilePath()
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 |
readObject(IndexedDiskElementDescriptor ded)
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.
|
public static final byte HEADER_SIZE_BYTES
public IndexedDisk(File file, IElementSerializer elementSerializer) throws IOException
file - elementSerializer - IOExceptionprotected <T> T readObject(IndexedDiskElementDescriptor ded) throws IOException, ClassNotFoundException
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.
ded - IOExceptionClassNotFoundExceptionprotected void move(IndexedDiskElementDescriptor ded, long newPosition) throws IOException
ded - newPosition - IOExceptionprotected boolean write(IndexedDiskElementDescriptor ded, byte[] data) throws IOException
data - ded - IOExceptionprotected <T> void writeObject(T obj,
long pos)
throws IOException
TODO: make this take a ded as well.
obj - pos - IOExceptionprotected long length()
throws IOException
IOException - If an I/O error occurs.public void close()
throws IOException
close in interface AutoCloseableIOExceptionprotected void reset()
throws IOException
IOExceptionprotected void truncate(long length)
throws IOException
length - the new length of the fileIOExceptionprotected String getFilePath()
protected boolean isEmpty()
throws IOException
IOException - If an I/O error occurs.Copyright © 2002–2022 The Apache Software Foundation. All rights reserved.