java.nio.channels

Class FileLock

public abstract class FileLock extends Object

Since: 1.4

Constructor Summary
protected FileLock(FileChannel channel, long position, long size, boolean shared)
Initializes the file lock.
Method Summary
FileChannelchannel()
Returns the file channel upon whose file this lock is held.
booleanisShared()
Tells whether this lock is shared.
abstract booleanisValid()
Tells whether or not this lock is valid.
booleanoverlaps(long position, long size)
Tells whether or not this lock overlaps the given lock range.
longposition()
Returns the position within the file of the first byte of the locked region.
abstract voidrelease()
Releases this lock.
longsize()
Returns the size of the locked region in bytes.
StringtoString()
Returns a string describing the range, type, and validity of this lock.

Constructor Detail

FileLock

protected FileLock(FileChannel channel, long position, long size, boolean shared)
Initializes the file lock.

Throws: IllegalArgumentException If the preconditions on the parameters do not hold

Method Detail

channel

public final FileChannel channel()
Returns the file channel upon whose file this lock is held.

isShared

public final boolean isShared()
Tells whether this lock is shared.

isValid

public abstract boolean isValid()
Tells whether or not this lock is valid.

overlaps

public final boolean overlaps(long position, long size)
Tells whether or not this lock overlaps the given lock range.

position

public final long position()
Returns the position within the file of the first byte of the locked region.

release

public abstract void release()
Releases this lock.

Throws: IOException If an error occurs ClosedChannelException If the locked channel is no longer open.

size

public final long size()
Returns the size of the locked region in bytes.

toString

public final String toString()
Returns a string describing the range, type, and validity of this lock.