FileLock


FileLock java.nio.channels

Java 1.4

A FileLock object is returned by the lock( ) and tryLock( ) methods of FileChannel and represents a lock on a file or a region of a file. See FileChannel for more information on file locking with those methods. When a lock is no longer required, it should be released with the release( ) method. A lock will also be released if the channel is closed, or when the virtual machine terminates. isValid( ) returns TRue if the lock has not yet been released, and returns false if it has been released.

The channel( ) , position( ) , size ( ) and isShared( ) methods return basic information about the lock: the FileChannel that was locked, the region of the file that was locked, and whether the lock is shared or exclusive. If the entire file is locked, then the size( ) method returns a value ( Long.MAX_VALUE ) that is much greater than the actual file size. If the underlying operating system does not support shared locks, then isShared( ) may return false even if a shared lock was requested . overlaps( ) is a convenience method that returns true if the position and size of this lock overlap the specified position and size.

 public abstract class  FileLock  {  // Protected Constructors  protected  FileLock  (FileChannel  channel  , long  position  , long  size  ,          boolean  shared  );  // Public Instance Methods  public final FileChannel  channel  ( );        public final boolean  isShared  ( );        public abstract boolean  isValid  ( );        public final boolean  overlaps  (long  position  , long  size  );        public final long  position  ( );        public abstract void  release  ( ) throws java.io.IOException;        public final long  size  ( );  // Public Methods Overriding Object  public final String  toString  ( );   } 

Returned By

FileChannel.{lock( ) , tryLock( )}



Java In A Nutshell
Java In A Nutshell, 5th Edition
ISBN: 0596007736
EAN: 2147483647
Year: 2004
Pages: 1220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net