|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.processmining.framework.log.rfb.io.ManagedRandomAccessFile
public class ManagedRandomAccessFile
This class represents the typical interface of a random access file, i.e.
the DataInput
and DataOutput
interfaces plus navigation
and closing functionality.
Within all instances of this class, a given limit of open files is ensured. The lightweight wrapper instances automatically care for restoring the underlying instance's state when it had been closed intermediately.
Notice that the wrapper's seek()
method has been implemented in a
lazy fashion, i.e. it will only access I/O when necessary.
Nested Class Summary | |
---|---|
protected static class |
ManagedRandomAccessFile.ShutdownHook
This class implements a shutdown hook, which will clear all files backing instances of the enclosing class from the file system at the moment, at which the JVM shuts down. |
Field Summary | |
---|---|
protected long |
currentFilePointer
|
protected java.io.File |
file
|
protected boolean |
isOpen
|
protected static int |
maxOpenFiles
Defines the maximal number of open random access files concurrently held by instances of this class |
protected static int |
openFilesCounter
Counts the global number of open random access files held by instances of this class |
protected static java.util.ArrayList<ManagedRandomAccessFile> |
openFilesList
Holds references of instances of this class, which currently hold an open random access file |
protected java.io.RandomAccessFile |
raf
|
protected static java.lang.String |
TEMP_FILE_PREFIX
Prefix for temporary buffer files. |
protected static java.lang.String |
TEMP_FILE_SUFFIX
Suffix for temporary buffer files. |
Constructor Summary | |
---|---|
ManagedRandomAccessFile()
Creates a new managed instance, which is based on the given file. |
|
ManagedRandomAccessFile(ManagedRandomAccessFile template)
Creates a new managed instance, which is based on the given file. |
Method Summary | |
---|---|
void |
close()
Closes this instance virtually (flushes and releases the managed file) |
protected void |
closeHandle()
Called by the static open file management facility, when the underlying file has to be closed due to open file limit restrictions. |
RandomAccessStorage |
copy()
Creates a clone, or copy, of this storage, having the exact same contents and the file pointer reset to zero. |
static void |
copyFile(java.io.File source,
java.io.File destination)
Copies the contents of the source file verbatim to the provided destination file. |
protected static java.io.File |
createTempFile()
Creates a new temporary file with the configured pre- and suffix in the system-wide temporary file directory. |
boolean |
delete()
Deletes the underlying file from the file system. |
void |
deleteOnExit()
Deletes the underlying file from the file system when the virtual machine is shut down. |
protected void |
finalize()
Cleans the actual file which has been wrapped from disk. |
long |
getFilePointer()
Retrieves the current offset within the managed file, from which the next read or write occurs. |
long |
length()
Retrieves the current size of the managed file |
protected java.io.RandomAccessFile |
raf()
Provides wrapped access to the managed random access file. |
boolean |
readBoolean()
Wrapped method from DataInput interface. |
byte |
readByte()
Wrapped method from DataInput interface. |
char |
readChar()
Wrapped method from DataInput interface. |
double |
readDouble()
Wrapped method from DataInput interface. |
float |
readFloat()
Wrapped method from DataInput interface. |
void |
readFully(byte[] arg0)
Wrapped method from DataInput interface. |
void |
readFully(byte[] arg0,
int arg1,
int arg2)
Wrapped method from DataInput interface. |
int |
readInt()
Wrapped method from DataInput interface. |
java.lang.String |
readLine()
Wrapped method from DataInput interface. |
long |
readLong()
Wrapped method from DataInput interface. |
short |
readShort()
Wrapped method from DataInput interface. |
int |
readUnsignedByte()
Wrapped method from DataInput interface. |
int |
readUnsignedShort()
Wrapped method from DataInput interface. |
java.lang.String |
readUTF()
Warning: custom implementation will expect different low-level byte encoding than e.g. |
protected static void |
releaseOpenFileSlot(ManagedRandomAccessFile customer)
Called by instances of this class to signal release of a currently held open file handle (when closing the instance). |
protected void |
reOpen()
Re-opens the managed random access file, implies retrieving an open file slot from the static management facilities. |
protected static void |
retrieveOpenFileSlot(ManagedRandomAccessFile customer)
Acquires an open file slot for the calling instance and registers it accordingly. |
void |
seek(long position)
Sets the file pointer offset to the given position. |
int |
skipBytes(int arg0)
Wrapped method from DataInput interface. |
void |
write(byte[] arg)
Wrapped method from DataOutput interface. |
void |
write(byte[] arg,
int arg1,
int arg2)
Wrapped method from DataOutput interface. |
void |
write(int val)
Wrapped method from DataOutput interface. |
void |
writeBoolean(boolean bool)
Wrapped method from DataOutput interface. |
void |
writeByte(int arg0)
Wrapped method from DataOutput interface. |
void |
writeBytes(java.lang.String arg0)
Wrapped method from DataOutput interface. |
void |
writeChar(int arg0)
Wrapped method from DataOutput interface. |
void |
writeChars(java.lang.String arg0)
Wrapped method from DataOutput interface. |
void |
writeDouble(double arg0)
Wrapped method from DataOutput interface. |
void |
writeFloat(float arg0)
Wrapped method from DataOutput interface. |
void |
writeInt(int arg0)
Wrapped method from DataOutput interface. |
void |
writeLong(long arg0)
Wrapped method from DataOutput interface. |
void |
writeShort(int arg0)
Wrapped method from DataOutput interface. |
void |
writeUTF(java.lang.String arg0)
Warning: This method uses a custom format to encode UTF-8 strings to bytes than specified in DataOutput. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String TEMP_FILE_PREFIX
protected static final java.lang.String TEMP_FILE_SUFFIX
protected static int openFilesCounter
protected static java.util.ArrayList<ManagedRandomAccessFile> openFilesList
protected static int maxOpenFiles
protected java.io.File file
protected java.io.RandomAccessFile raf
protected long currentFilePointer
protected boolean isOpen
Constructor Detail |
---|
public ManagedRandomAccessFile() throws java.io.IOException
aFile
- The file which to access in a random fashion.
java.io.IOException
public ManagedRandomAccessFile(ManagedRandomAccessFile template) throws java.io.IOException
template
- The template to create a clone from.aFile
- File which is to be backing the clone to be created.
java.io.IOException
Method Detail |
---|
protected static void retrieveOpenFileSlot(ManagedRandomAccessFile customer) throws java.io.IOException
customer
- Calling instance requiring an open file slot(this
reference)
java.io.IOException
protected static void releaseOpenFileSlot(ManagedRandomAccessFile customer) throws java.io.IOException
customer
- Calling instance freeing an open file slot(this
reference)
java.io.IOException
public boolean delete() throws java.io.IOException
Warning: The usage contract is, that after calling this method no reading or modifying method may be called. Otherwise, unexpected results may be produced.
java.io.IOException
public void deleteOnExit() throws java.io.IOException
Warning: The usage contract is, that after calling this method no reading or modifying method may be called. Otherwise, unexpected results may be produced.
java.io.IOException
public void close() throws java.io.IOException
close
in interface RandomAccessStorage
java.io.IOException
public long getFilePointer()
getFilePointer
in interface RandomAccessStorage
public long length() throws java.io.IOException
length
in interface RandomAccessStorage
java.io.IOException
public void seek(long position)
Notice that this method behaves different from the identical
method in RandomAccessFile
, in that it does not
necessarily trigger a low-level I/O call, as this class
implements lazy seeking (seeking is only performed at the
point in time, at which it becomes necessary for access).
seek
in interface RandomAccessStorage
position
- The offset in bytes from the beginning of the
managed file, at which to read or write the next data.protected void closeHandle() throws java.io.IOException
Usage contract: This method must only be called on instances which are guaranteed to hold an open file reference at the point of calling!
java.io.IOException
protected void reOpen() throws java.io.IOException
java.io.IOException
protected java.io.RandomAccessFile raf() throws java.io.IOException
java.io.IOException
public void write(int val) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
write
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void write(byte[] arg) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
write
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void write(byte[] arg, int arg1, int arg2) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
write
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeBoolean(boolean bool) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeBoolean
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeByte(int arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeByte
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeShort(int arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeShort
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeChar(int arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeChar
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeInt(int arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeInt
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeLong(long arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeLong
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeFloat(float arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeFloat
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeDouble(double arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeDouble
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeBytes(java.lang.String arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeBytes
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeChars(java.lang.String arg0) throws java.io.IOException
DataOutput
interface.
Preserves the internal state of the managed proxy instance.
writeChars
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void writeUTF(java.lang.String arg0) throws java.io.IOException
Preserves the internal state of the managed proxy instance.
writeUTF
in interface java.io.DataOutput
java.io.IOException
DataOutput
public void readFully(byte[] arg0) throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readFully
in interface java.io.DataInput
java.io.IOException
DataInput
public void readFully(byte[] arg0, int arg1, int arg2) throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readFully
in interface java.io.DataInput
java.io.IOException
DataInput
public int skipBytes(int arg0) throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
skipBytes
in interface java.io.DataInput
skipBytes
in interface RandomAccessStorage
java.io.IOException
DataInput
public boolean readBoolean() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readBoolean
in interface java.io.DataInput
java.io.IOException
DataInput
public byte readByte() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readByte
in interface java.io.DataInput
java.io.IOException
DataInput
public int readUnsignedByte() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
DataInput
public short readShort() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readShort
in interface java.io.DataInput
java.io.IOException
DataInput
public int readUnsignedShort() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
DataInput
public char readChar() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readChar
in interface java.io.DataInput
java.io.IOException
DataInput
public int readInt() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readInt
in interface java.io.DataInput
java.io.IOException
DataInput
public long readLong() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readLong
in interface java.io.DataInput
java.io.IOException
DataInput
public float readFloat() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readFloat
in interface java.io.DataInput
java.io.IOException
DataInput
public double readDouble() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readDouble
in interface java.io.DataInput
java.io.IOException
DataInput
public java.lang.String readLine() throws java.io.IOException
DataInput
interface.
Preserves the internal state of the managed proxy instance.
readLine
in interface java.io.DataInput
java.io.IOException
DataInput
public java.lang.String readUTF() throws java.io.IOException
RandomAccessFile
!
Preserves the internal state of the managed proxy instance.
readUTF
in interface java.io.DataInput
java.io.IOException
DataInput
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public static void copyFile(java.io.File source, java.io.File destination) throws java.io.IOException
This implementation uses the Java NIO API to realize a most efficient copy procedure. The NIO API should automatically be mapped to highly efficient operating system level functionality available in the respective host operating system.
source
- File to be copied.destination
- Destination of copy.
java.io.IOException
public RandomAccessStorage copy() throws java.io.IOException
RandomAccessStorage
copy
in interface RandomAccessStorage
java.io.IOException
protected static java.io.File createTempFile() throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |