public class DiskSpaceCheckingRandomAccessBufferFactory extends java.lang.Object implements LockableRandomAccessBufferFactory, DiskSpaceChecker, FileRandomAccessBufferFactory
Constructor and Description |
---|
DiskSpaceCheckingRandomAccessBufferFactory(LockableRandomAccessBufferFactory underlying,
java.io.File dir,
long minDiskSpace) |
Modifier and Type | Method and Description |
---|---|
boolean |
checkDiskSpace(java.io.File file,
int toWrite,
int bufferSize)
Is there enough space to extend the file?
|
PooledFileRandomAccessBuffer |
createNewRAF(java.io.File file,
long size,
java.util.Random random)
Create a new RAF for a specified file, which must exist but be 0 bytes long.
|
LockableRandomAccessBuffer |
makeRAF(byte[] initialContents,
int offset,
int size,
boolean readOnly)
Create a bucket with specified initial contents.
|
LockableRandomAccessBuffer |
makeRAF(long size)
Create a bucket.
|
void |
setMinDiskSpace(long min) |
java.lang.String |
toString() |
public DiskSpaceCheckingRandomAccessBufferFactory(LockableRandomAccessBufferFactory underlying, java.io.File dir, long minDiskSpace)
public void setMinDiskSpace(long min)
public LockableRandomAccessBuffer makeRAF(long size) throws java.io.IOException
LockableRandomAccessBufferFactory
makeRAF
in interface LockableRandomAccessBufferFactory
size
- The maximum size of the data. Most factories will pre-allocate this space, and
it may not be exceeded. However we do not guarantee that any I/O operation will complete;
even if we have pre-allocated the disk space, we may be unable to write to it because of
e.g. a hardware error.java.io.IOException
- If an I/O error prevented the operation.public LockableRandomAccessBuffer makeRAF(byte[] initialContents, int offset, int size, boolean readOnly) throws java.io.IOException
LockableRandomAccessBufferFactory
makeRAF
in interface LockableRandomAccessBufferFactory
initialContents
- Byte array from which to copy data. Data will be copied even if the
underlying implementation is a byte array, for reasons of consistency.offset
- Offset within the array to start copying data from.size
- Number of bytes to copy i.e. length of the new RandomAccessBuffer.java.io.IOException
- If an I/O error prevented the operation.public java.lang.String toString()
toString
in class java.lang.Object
public PooledFileRandomAccessBuffer createNewRAF(java.io.File file, long size, java.util.Random random) throws java.io.IOException
createNewRAF
in interface FileRandomAccessBufferFactory
InsufficientDiskSpaceException
- If there is not enough disk space.java.io.IOException
- If some other disk I/O error occurs.public boolean checkDiskSpace(java.io.File file, int toWrite, int bufferSize)
DiskSpaceChecker
checkDiskSpace
in interface DiskSpaceChecker
file
- The current filenametoWrite
- Length of the proposed writebufferSize
- The caller only checks disk space when the number of bytes written since
the last check exceeds this value.