com.mckoi.store
Class ScatteringStoreDataAccessor

java.lang.Object
  extended by com.mckoi.store.ScatteringStoreDataAccessor

public class ScatteringStoreDataAccessor
extends java.lang.Object

An implementation of StoreDataAccessor that scatters the addressible data resource across multiple files in the file system. When one store data resource reaches a certain threshold size, the content 'flows' over to the next file.

Author:
Tobias Downer

Constructor Summary
ScatteringStoreDataAccessor(java.io.File path, java.lang.String file_name, java.lang.String first_ext, long max_slice_size)
          Constructs the store data accessor.
 
Method Summary
 void close()
          Closes the underlying data area representation.
 void convertToScatteringStore(java.io.File f)
          Given a file, this will convert to a scattering file store with files no larger than the maximum slice size.
 boolean delete()
          Deletes the data area resource.
 boolean exists()
          Returns true if the resource exists.
 long getSize()
          Returns the current size of the underlying data area.
 void open(boolean read_only)
          Opens the underlying data area representation.
 void read(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.
 void setSize(long length)
          Sets the size of the underlying data area to the given size.
 void synch()
          Synchronizes the data area by forcing any data out of the OS buffers onto the disk.
 void write(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScatteringStoreDataAccessor

public ScatteringStoreDataAccessor(java.io.File path,
                                   java.lang.String file_name,
                                   java.lang.String first_ext,
                                   long max_slice_size)
Constructs the store data accessor.

Method Detail

convertToScatteringStore

public void convertToScatteringStore(java.io.File f)
                              throws java.io.IOException
Given a file, this will convert to a scattering file store with files no larger than the maximum slice size.

Throws:
java.io.IOException

open

public void open(boolean read_only)
          throws java.io.IOException
Opens the underlying data area representation. If the resource doesn't exist then it is created and the size is set to 0.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the underlying data area representation.

Throws:
java.io.IOException

delete

public boolean delete()
Deletes the data area resource. Returns true if the delete was successful.


exists

public boolean exists()
Returns true if the resource exists.


read

public void read(long position,
                 byte[] buf,
                 int off,
                 int len)
          throws java.io.IOException
Reads a block of data from the underlying data area at the given position into the byte array at the given offset.

Throws:
java.io.IOException

write

public void write(long position,
                  byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Writes a block of data to the underlying data area from the byte array at the given offset.

Throws:
java.io.IOException

setSize

public void setSize(long length)
             throws java.io.IOException
Sets 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.

Throws:
java.io.IOException

getSize

public long getSize()
             throws java.io.IOException
Returns the current size of the underlying data area.

Throws:
java.io.IOException

synch

public void synch()
           throws java.io.IOException
Synchronizes the data area by forcing any data out of the OS buffers onto the disk.

Throws:
java.io.IOException