public abstract class BaseFileBucket extends java.lang.Object implements RandomAccessBucket
Modifier and Type | Field and Description |
---|---|
protected long |
fileRestartCounter |
static int |
MAGIC |
protected static java.lang.String |
tempDir |
Modifier | Constructor and Description |
---|---|
protected |
BaseFileBucket() |
protected |
BaseFileBucket(java.io.DataInputStream dis) |
|
BaseFileBucket(java.io.File file,
boolean deleteOnExit)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract boolean |
createFileOnly()
If true, we will fail if the file already exist.
|
protected void |
deleteFile()
Actually delete the underlying file.
|
protected abstract boolean |
deleteOnExit() |
protected abstract boolean |
deleteOnFree() |
void |
free()
Free the bucket, if supported.
|
void |
free(boolean forceFree) |
abstract java.io.File |
getFile()
Returns the file object this buckets data is kept in.
|
java.io.InputStream |
getInputStream()
Returns an InputStream that reads data from this Bucket.
|
java.io.InputStream |
getInputStreamUnbuffered() |
java.lang.String |
getName()
Returns a name for the bucket, may be used to identify them in
certain in certain situations.
|
java.io.OutputStream |
getOutputStream()
Returns an OutputStream that is used to put data in this Bucket, from the
beginning.
|
java.io.OutputStream |
getOutputStreamUnbuffered()
Get an OutputStream which is not buffered.
|
protected long |
getPersistentTempID() |
static java.lang.String |
getTempDir()
Return directory used for temp files.
|
protected java.io.File |
getTempfile()
Create a temporary file in the same directory as this file.
|
void |
onResume(ClientContext context)
Called after restarting.
|
protected void |
setDeleteOnExit(java.io.File file) |
static void |
setTempDir(java.lang.String dirName)
Set temp file directory.
|
long |
size()
Returns the amount of data currently in this bucket in bytes.
|
Bucket[] |
split(int splitSize) |
void |
storeTo(java.io.DataOutputStream dos)
Write enough data to reconstruct the Bucket, or throw UnsupportedOperationException.
|
protected abstract boolean |
tempFileAlreadyExists()
If true, then the file is temporary and must already exist, so we will just open it.
|
LockableRandomAccessBuffer |
toRandomAccessBuffer()
Convert the Bucket to a LockableRandomAccessBuffer.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
createShadow
isReadOnly, setReadOnly
protected long fileRestartCounter
protected static java.lang.String tempDir
public static final int MAGIC
public BaseFileBucket(java.io.File file, boolean deleteOnExit)
file
- deleteOnExit
- If true, call File.deleteOnExit() on the file.
WARNING: Delete on exit is a memory leak: The filenames are kept until the JVM exits, and
cannot be removed even when the file has been deleted! It should only be used where it is
ESSENTIAL! Note that if you want temp files to be deleted on exit, you also need to override
deleteOnExit().protected BaseFileBucket()
protected BaseFileBucket(java.io.DataInputStream dis) throws java.io.IOException, StorageFormatException
java.io.IOException
StorageFormatException
protected void setDeleteOnExit(java.io.File file)
public java.io.OutputStream getOutputStreamUnbuffered() throws java.io.IOException
Bucket
getOutputStreamUnbuffered
in interface Bucket
java.io.IOException
public java.io.OutputStream getOutputStream() throws java.io.IOException
Bucket
getOutputStream
in interface Bucket
java.io.IOException
protected abstract boolean tempFileAlreadyExists()
protected abstract boolean createFileOnly()
protected abstract boolean deleteOnExit()
protected abstract boolean deleteOnFree()
protected java.io.File getTempfile() throws java.io.IOException
java.io.IOException
public java.io.InputStream getInputStreamUnbuffered() throws java.io.IOException
getInputStreamUnbuffered
in interface Bucket
java.io.IOException
public java.io.InputStream getInputStream() throws java.io.IOException
Bucket
getInputStream
in interface Bucket
java.io.IOException
public java.lang.String getName()
Bucket
public long size()
Bucket
protected void deleteFile()
public static java.lang.String getTempDir()
public static void setTempDir(java.lang.String dirName)
The directory must exist.
public Bucket[] split(int splitSize)
public void free()
Bucket
public void free(boolean forceFree)
public java.lang.String toString()
toString
in class java.lang.Object
public abstract java.io.File getFile()
public void onResume(ClientContext context) throws ResumeFailedException
Bucket
onResume
in interface Bucket
context
- All the necessary runtime support will be on this object.ResumeFailedException
public void storeTo(java.io.DataOutputStream dos) throws java.io.IOException
Bucket
public LockableRandomAccessBuffer toRandomAccessBuffer() throws java.io.IOException
RandomAccessBucket
toRandomAccessBuffer
in interface RandomAccessBucket
java.io.IOException
protected long getPersistentTempID()