Package com.mckoi.store
Class IOStoreDataAccessor
- java.lang.Object
-
- com.mckoi.store.IOStoreDataAccessor
-
- All Implemented Interfaces:
StoreDataAccessor
class IOStoreDataAccessor extends java.lang.Object implements StoreDataAccessor
An implementation of StoreDataAccessor that uses the standard Java IO API to access data in some underlying file in the filesystem.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.RandomAccessFiledataThe underlying RandomAccessFile containing the data.private java.io.FilefileThe File object representing the file in the file system.private booleanis_openTrue if the file is open.private java.lang.ObjectlockA lock because access to the data is stateful.private longsizeThe size of the data area.
-
Constructor Summary
Constructors Constructor Description IOStoreDataAccessor(java.io.File file)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying data area representation.booleandelete()Deletes the data area resource.booleanexists()Returns true if the resource exists.longgetSize()Returns the current size of the underlying data area.voidopen(boolean is_read_only)Opens the underlying data area representation.voidread(long position, byte[] buf, int off, int len)Reads a block of data from the underlying data area at the given position into the byte array at the given offset.voidsetSize(long new_size)Sets the size of the underlying data area to the given size.voidsynch()Synchronizes the data area by forcing any data out of the OS buffers onto the disk.voidwrite(long position, byte[] buf, int off, int len)Writes a block of data to the underlying data area from the byte array at the given offset.
-
-
-
Field Detail
-
lock
private java.lang.Object lock
A lock because access to the data is stateful.
-
file
private java.io.File file
The File object representing the file in the file system.
-
data
private java.io.RandomAccessFile data
The underlying RandomAccessFile containing the data.
-
size
private long size
The size of the data area.
-
is_open
private boolean is_open
True if the file is open.
-
-
Method Detail
-
open
public void open(boolean is_read_only) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorOpens the underlying data area representation. If the resource doesn't exist then it is created and the size is set to 0.- Specified by:
openin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorCloses the underlying data area representation.- Specified by:
closein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
delete
public boolean delete()
Description copied from interface:StoreDataAccessorDeletes the data area resource. Returns true if the delete was successful.- Specified by:
deletein interfaceStoreDataAccessor
-
exists
public boolean exists()
Description copied from interface:StoreDataAccessorReturns true if the resource exists.- Specified by:
existsin interfaceStoreDataAccessor
-
read
public void read(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorReads a block of data from the underlying data area at the given position into the byte array at the given offset.- Specified by:
readin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
write
public void write(long position, byte[] buf, int off, int len) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorWrites a block of data to the underlying data area from the byte array at the given offset.- Specified by:
writein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
setSize
public void setSize(long new_size) throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorSets the size of the underlying data area to the given size. If the size of the data area is increased, the content between the old size and the new size is implementation defined.- Specified by:
setSizein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
getSize
public long getSize() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorReturns the current size of the underlying data area.- Specified by:
getSizein interfaceStoreDataAccessor- Throws:
java.io.IOException
-
synch
public void synch() throws java.io.IOExceptionDescription copied from interface:StoreDataAccessorSynchronizes the data area by forcing any data out of the OS buffers onto the disk.- Specified by:
synchin interfaceStoreDataAccessor- Throws:
java.io.IOException
-
-