org.apfloat.internal
Class DiskDataStorage

java.lang.Object
  extended by org.apfloat.spi.DataStorage
      extended by org.apfloat.internal.DiskDataStorage
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DoubleDiskDataStorage, FloatDiskDataStorage, IntDiskDataStorage, LongDiskDataStorage

public abstract class DiskDataStorage
extends DataStorage

Abstract base class for disk-based data storage, containing the common functionality independent of the element type.

Version:
1.6.2
Author:
Mikko Tommila
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apfloat.spi.DataStorage
DataStorage.AbstractIterator, DataStorage.Iterator
 
Field Summary
 
Fields inherited from class org.apfloat.spi.DataStorage
READ, READ_WRITE, WRITE
 
Constructor Summary
protected DiskDataStorage()
          Default constructor.
protected DiskDataStorage(DiskDataStorage diskDataStorage, long offset, long length)
          Subsequence constructor.
 
Method Summary
protected static int getBlockSize()
          Convenience method for getting the block size (in bytes) for the current ApfloatContext.
protected  FileChannel getFileChannel()
          The FileChannel of the underlying disk file.
protected  String getFilename()
          Filename of the underlying disk data storage.
protected abstract  int getUnitSize()
          Size of the element type, in bytes.
protected  void implCopyFrom(DataStorage dataStorage, long size)
          Copies the specified number of elements from another data storage to this data storage.
protected  long implGetSize()
          Return the size of the whole data storage, not including sub-sequence settings.
protected  void implSetSize(long size)
          Sets the size of the data storage.
protected  void transferFrom(ReadableByteChannel in, long position, long size)
          Transfer from a readable channel, possibly in multiple chunks.
protected  void transferTo(WritableByteChannel out, long position, long size)
          Transfer to a writable channel, possibly in multiple chunks.
 
Methods inherited from class org.apfloat.spi.DataStorage
copyFrom, copyFrom, getArray, getOffset, getSize, getTransposedArray, implGetArray, implGetTransposedArray, implSubsequence, isReadOnly, isSubsequenced, iterator, setReadOnly, setSize, subsequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiskDataStorage

protected DiskDataStorage()
                   throws ApfloatRuntimeException
Default constructor.

Throws:
ApfloatRuntimeException

DiskDataStorage

protected DiskDataStorage(DiskDataStorage diskDataStorage,
                          long offset,
                          long length)
Subsequence constructor.

Parameters:
diskDataStorage - The originating data storage.
offset - The subsequence starting position.
length - The subsequence length.
Method Detail

implCopyFrom

protected void implCopyFrom(DataStorage dataStorage,
                            long size)
                     throws ApfloatRuntimeException
Description copied from class: DataStorage
Copies the specified number of elements from another data storage to this data storage. The validity of the arguments of this method do not need to be checked.

Specified by:
implCopyFrom in class DataStorage
Parameters:
dataStorage - The data storage where the data should be copied from.
size - The number of elements to be copied.
Throws:
ApfloatRuntimeException

implGetSize

protected long implGetSize()
                    throws ApfloatRuntimeException
Description copied from class: DataStorage
Return the size of the whole data storage, not including sub-sequence settings.

Specified by:
implGetSize in class DataStorage
Returns:
The size of the whole data storage, not including sub-sequence settings.
Throws:
ApfloatRuntimeException

implSetSize

protected void implSetSize(long size)
                    throws ApfloatRuntimeException
Description copied from class: DataStorage
Sets the size of the data storage. The validity of the arguments of this method do not need to be checked.

Specified by:
implSetSize in class DataStorage
Parameters:
size - The size of the data storage.
Throws:
ApfloatRuntimeException

transferFrom

protected void transferFrom(ReadableByteChannel in,
                            long position,
                            long size)
                     throws ApfloatRuntimeException
Transfer from a readable channel, possibly in multiple chunks.

Parameters:
in - Input channel.
position - Start position of transfer.
size - Total number of bytes to transfer.
Throws:
ApfloatRuntimeException

transferTo

protected void transferTo(WritableByteChannel out,
                          long position,
                          long size)
                   throws ApfloatRuntimeException
Transfer to a writable channel, possibly in multiple chunks.

Parameters:
out - Output channel.
position - Start position of transfer.
size - Total number of bytes to transfer.
Throws:
ApfloatRuntimeException

getBlockSize

protected static int getBlockSize()
Convenience method for getting the block size (in bytes) for the current ApfloatContext.

Returns:
I/O block size, in bytes.

getUnitSize

protected abstract int getUnitSize()
Size of the element type, in bytes.

Returns:
Size of the element type, in bytes.

getFilename

protected final String getFilename()
Filename of the underlying disk data storage.

Returns:
Filename of the underlying disk data storage.

getFileChannel

protected final FileChannel getFileChannel()
The FileChannel of the underlying disk file.

Returns:
The FileChannel of the underlying disk file.