Package org.apfloat.internal
Class DiskDataStorage
- java.lang.Object
-
- org.apfloat.spi.DataStorage
-
- org.apfloat.internal.DiskDataStorage
-
- All Implemented Interfaces:
java.io.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.14.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDiskDataStorage.FileStorageprivate static classDiskDataStorage.FileStorageReference-
Nested classes/interfaces inherited from class org.apfloat.spi.DataStorage
DataStorage.AbstractIterator, DataStorage.Iterator
-
-
Field Summary
Fields Modifier and Type Field Description private static booleancleanUpprivate DiskDataStorage.FileStoragefileStorageprivate static java.lang.ref.ReferenceQueue<DiskDataStorage.FileStorage>referenceQueueprivate static java.util.Set<DiskDataStorage.FileStorageReference>referencesprivate static longserialVersionUIDprivate static java.lang.ThreadLocal<java.lang.ref.SoftReference<java.nio.ByteBuffer>>threadLocalprivate static longTIMEOUTprivate static java.nio.channels.ReadableByteChannelZERO_CHANNEL-
Fields inherited from class org.apfloat.spi.DataStorage
READ, READ_WRITE, WRITE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDiskDataStorage()Default constructor.protectedDiskDataStorage(DiskDataStorage diskDataStorage, long offset, long length)Subsequence constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) static voidcleanUp()protected abstract ArrayAccesscreateArrayAccess(int mode, int startColumn, int columns, int rows)Create an empty ArrayAccess.private static DiskDataStorage.FileStoragecreateFileStorage()protected abstract ArrayAccesscreateTransposedArrayAccess(int mode, int startColumn, int columns, int rows)Create an empty transposed ArrayAccess.private static voidforceFreeFileStorage()private static voidfreeFileStorage()(package private) static voidgc()protected static intgetBlockSize()Convenience method for getting the block size (in bytes) for the currentApfloatContext.private static java.nio.ByteBuffergetDirectByteBuffer()protected java.nio.channels.FileChannelgetFileChannel()TheFileChannelof the underlying disk file.protected java.lang.StringgetFilename()Filename of the underlying disk data storage.protected abstract intgetUnitSize()Size of the element type, in bytes.protected voidimplCopyFrom(DataStorage dataStorage, long size)Copies the specified number of elements from another data storage to this data storage.protected ArrayAccessimplGetArray(int mode, int startColumn, int columns, int rows)Maps a block of data to a memory array when the data is treated as a matrix.protected longimplGetSize()Return the size of the whole data storage, not including sub-sequence settings.protected ArrayAccessimplGetTransposedArray(int mode, int startColumn, int columns, int rows)Maps a transposed block of data to a memory array when the data is treated as a matrix.protected voidimplSetSize(long size)Sets the size of the data storage.booleanisCached()Is this object cached in memory.private voidpad(long position, long size)private voidreadToArray(long readPosition, ArrayAccess arrayAccess, int writePosition, int length)private static voidreferenceFileStorage(DiskDataStorage.FileStorage fileStorage)protected voidsetArray(ArrayAccess arrayAccess, int startColumn, int columns, int rows)Write the data back to the same location in the file that was retrieved withimplGetArray(int,int,int,int).protected voidsetTransposedArray(ArrayAccess arrayAccess, int startColumn, int columns, int rows)Write the data back to the same location in the file that was retrieved withimplGetTransposedArray(int,int,int,int).protected voidtransferFrom(java.nio.channels.ReadableByteChannel in, long position, long size)Transfer from a readable channel, possibly in multiple chunks.protected voidtransferTo(java.nio.channels.WritableByteChannel out, long position, long size)Transfer to a writable channel, possibly in multiple chunks.private voidwriteFromArray(ArrayAccess arrayAccess, int readPosition, long writePosition, int length)-
Methods inherited from class org.apfloat.spi.DataStorage
copyFrom, copyFrom, getArray, getArray, getOffset, getSize, getTransposedArray, implGetArray, implSubsequence, isReadOnly, isSubsequenced, iterator, setReadOnly, setSize, subsequence
-
-
-
-
Field Detail
-
ZERO_CHANNEL
private static final java.nio.channels.ReadableByteChannel ZERO_CHANNEL
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
TIMEOUT
private static final long TIMEOUT
- See Also:
- Constant Field Values
-
referenceQueue
private static java.lang.ref.ReferenceQueue<DiskDataStorage.FileStorage> referenceQueue
-
references
private static java.util.Set<DiskDataStorage.FileStorageReference> references
-
threadLocal
private static java.lang.ThreadLocal<java.lang.ref.SoftReference<java.nio.ByteBuffer>> threadLocal
-
cleanUp
private static boolean cleanUp
-
fileStorage
private DiskDataStorage.FileStorage fileStorage
-
-
Constructor Detail
-
DiskDataStorage
protected DiskDataStorage() throws ApfloatRuntimeExceptionDefault 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
-
isCached
public boolean isCached()
Description copied from class:DataStorageIs this object cached in memory.- Specified by:
isCachedin classDataStorage- Returns:
trueif this object is cached in memory,falseif not.
-
implCopyFrom
protected void implCopyFrom(DataStorage dataStorage, long size) throws ApfloatRuntimeException
Description copied from class:DataStorageCopies 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:
implCopyFromin classDataStorage- 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 ApfloatRuntimeExceptionDescription copied from class:DataStorageReturn the size of the whole data storage, not including sub-sequence settings.- Specified by:
implGetSizein classDataStorage- Returns:
- The size of the whole data storage, not including sub-sequence settings.
- Throws:
ApfloatRuntimeException
-
implSetSize
protected void implSetSize(long size) throws ApfloatRuntimeExceptionDescription copied from class:DataStorageSets the size of the data storage. The validity of the arguments of this method do not need to be checked.- Specified by:
implSetSizein classDataStorage- Parameters:
size- The size of the data storage.- Throws:
ApfloatRuntimeException
-
implGetArray
protected ArrayAccess implGetArray(int mode, int startColumn, int columns, int rows) throws ApfloatRuntimeException
Description copied from class:DataStorageMaps a block of data to a memory array when the data is treated as a matrix. The validity of the arguments of this method do not need to be checked.- Specified by:
implGetArrayin classDataStorage- Parameters:
mode- Whether the array is prepared for reading, writing or both. The value should beDataStorage.READ,DataStorage.WRITEor a combination of these.startColumn- The starting column where data is read.columns- The number of columns of data to read.rows- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.- Returns:
- Access to an array of size
columnsxrowscontaining the data. - Throws:
ApfloatRuntimeException
-
implGetTransposedArray
protected ArrayAccess implGetTransposedArray(int mode, int startColumn, int columns, int rows) throws ApfloatRuntimeException
Description copied from class:DataStorageMaps a transposed block of data to a memory array when the data is treated as a matrix. The validity of the arguments of this method do not need to be checked.- Specified by:
implGetTransposedArrayin classDataStorage- Parameters:
mode- Whether the array is prepared for reading, writing or both. The value should beDataStorage.READ,DataStorage.WRITEor a combination of these.startColumn- The starting column where data is read.columns- The number of columns of data to read.rows- The number of rows of data to read. This should be equivalent to n1, number of rows in the matrix.- Returns:
- Access to an array of size
columnsxrowscontaining the transposed data. - Throws:
ApfloatRuntimeException
-
setArray
protected void setArray(ArrayAccess arrayAccess, int startColumn, int columns, int rows) throws ApfloatRuntimeException
Write the data back to the same location in the file that was retrieved withimplGetArray(int,int,int,int).- Parameters:
arrayAccess- The transposed array access.startColumn- The starting column where data is stored.columns- The number of columns of data.rows- The number of rows of data.- Throws:
ApfloatRuntimeException- Since:
- 1.7.0
-
setTransposedArray
protected void setTransposedArray(ArrayAccess arrayAccess, int startColumn, int columns, int rows) throws ApfloatRuntimeException
Write the data back to the same location in the file that was retrieved withimplGetTransposedArray(int,int,int,int).- Parameters:
arrayAccess- The transposed array access.startColumn- The starting column where data is stored.columns- The number of columns of data.rows- The number of rows of data.- Throws:
ApfloatRuntimeException- Since:
- 1.7.0
-
readToArray
private void readToArray(long readPosition, ArrayAccess arrayAccess, int writePosition, int length) throws ApfloatRuntimeException- Throws:
ApfloatRuntimeException
-
writeFromArray
private void writeFromArray(ArrayAccess arrayAccess, int readPosition, long writePosition, int length) throws ApfloatRuntimeException
- Throws:
ApfloatRuntimeException
-
createArrayAccess
protected abstract ArrayAccess createArrayAccess(int mode, int startColumn, int columns, int rows)
Create an empty ArrayAccess.- Parameters:
mode- Whether the array is prepared for reading, writing or both. The value should beDataStorage.READ,DataStorage.WRITEor a combination of these.startColumn- The starting column where data is stored.columns- The number of columns of data.rows- The number of rows of data.- Returns:
- Access to an empty array of the specified size and position.
- Since:
- 1.7.0
-
createTransposedArrayAccess
protected abstract ArrayAccess createTransposedArrayAccess(int mode, int startColumn, int columns, int rows)
Create an empty transposed ArrayAccess.- Parameters:
mode- Whether the array is prepared for reading, writing or both. The value should beDataStorage.READ,DataStorage.WRITEor a combination of these.startColumn- The starting column where data is stored.columns- The number of columns of data.rows- The number of rows of data.- Returns:
- Access to an empty array of the specified size and position.
- Since:
- 1.7.0
-
transferFrom
protected void transferFrom(java.nio.channels.ReadableByteChannel in, long position, long size) throws ApfloatRuntimeExceptionTransfer 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(java.nio.channels.WritableByteChannel out, long position, long size) throws ApfloatRuntimeExceptionTransfer 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 currentApfloatContext.- 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 java.lang.String getFilename()
Filename of the underlying disk data storage.- Returns:
- Filename of the underlying disk data storage.
-
getFileChannel
protected final java.nio.channels.FileChannel getFileChannel()
TheFileChannelof the underlying disk file.- Returns:
- The
FileChannelof the underlying disk file.
-
cleanUp
static void cleanUp() throws ApfloatRuntimeException- Throws:
ApfloatRuntimeException
-
gc
static void gc() throws ApfloatRuntimeException- Throws:
ApfloatRuntimeException
-
pad
private void pad(long position, long size) throws java.io.IOException, ApfloatRuntimeException- Throws:
java.io.IOExceptionApfloatRuntimeException
-
createFileStorage
private static DiskDataStorage.FileStorage createFileStorage() throws ApfloatInternalException
- Throws:
ApfloatInternalException
-
referenceFileStorage
private static void referenceFileStorage(DiskDataStorage.FileStorage fileStorage) throws ApfloatInternalException
- Throws:
ApfloatInternalException
-
freeFileStorage
private static void freeFileStorage()
-
forceFreeFileStorage
private static void forceFreeFileStorage() throws ApfloatInternalException- Throws:
ApfloatInternalException
-
getDirectByteBuffer
private static java.nio.ByteBuffer getDirectByteBuffer()
-
-