org.entityfs.util.io
Class LockAwareRandomAccessFile
java.lang.Object
java.io.RandomAccessFile
org.entityfs.util.io.LockAwareRandomAccessFile
- All Implemented Interfaces:
- Closeable, DataInput, DataOutput
public class LockAwareRandomAccessFile
- extends RandomAccessFile
A RandomAccessFile
that keeps a reference to the read or write lock
of the open EFile
. It is required that the lock is held by the
calling thread when it is calling any of the methods on instances of this
class. When the file is closed, the lock is unlocked if it is still locked.
FileDescriptor
:s and FileChannel
:s from this class are not
lock-aware.
Instances of this class are not thread safe.
- Since:
- 1.0
- Author:
- Karl Gustafsson
- See Also:
LockAwareRandomAccessFileFactoryImpl
Method Summary |
void |
close()
This will unlock the write lock if it is still locked by the current
thread. |
long |
length()
|
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
|
void |
setLength(long l)
|
void |
write(byte[] b)
|
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
Methods inherited from class java.io.RandomAccessFile |
getChannel, getFD, getFilePointer, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, seek, skipBytes, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LockAwareRandomAccessFile
public LockAwareRandomAccessFile(String name,
RandomAccessMode mode,
EntityLock lock)
throws FileNotFoundException
- Throws:
FileNotFoundException
LockAwareRandomAccessFile
public LockAwareRandomAccessFile(File f,
RandomAccessMode mode,
EntityLock lock)
throws FileNotFoundException
- Throws:
FileNotFoundException
close
public void close()
throws IOException
- This will unlock the write lock if it is still locked by the current
thread.
- Specified by:
close
in interface Closeable
- Overrides:
close
in class RandomAccessFile
- Throws:
IOException
length
public long length()
throws IOException
- Overrides:
length
in class RandomAccessFile
- Throws:
IOException
read
public int read()
throws IOException
- Overrides:
read
in class RandomAccessFile
- Throws:
IOException
read
public int read(byte[] b)
throws IOException
- Overrides:
read
in class RandomAccessFile
- Throws:
IOException
read
public int read(byte[] b,
int off,
int len)
throws IOException
- Overrides:
read
in class RandomAccessFile
- Throws:
IOException
setLength
public void setLength(long l)
throws IOException
- Overrides:
setLength
in class RandomAccessFile
- Throws:
IOException
write
public void write(int b)
throws IOException
- Specified by:
write
in interface DataOutput
- Overrides:
write
in class RandomAccessFile
- Throws:
IOException
write
public void write(byte[] b,
int off,
int len)
throws IOException
- Specified by:
write
in interface DataOutput
- Overrides:
write
in class RandomAccessFile
- Throws:
IOException
write
public void write(byte[] b)
throws IOException
- Specified by:
write
in interface DataOutput
- Overrides:
write
in class RandomAccessFile
- Throws:
IOException