source: trunk/gcc/libjava/java/nio/channels/FileLock.java

Last change on this file was 1389, checked in by bird, 21 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.6 KB
Line 
1/* FileLock.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.nio.channels;
39
40import java.io.IOException;
41
42/**
43 * @since 1.4
44 */
45public abstract class FileLock
46{
47 FileChannel channel;
48 long position;
49 long size;
50 boolean shared;
51
52 /**
53 * Initializes the file lock.
54 *
55 * @exception IllegalArgumentException If the preconditions on the parameters do not hold
56 */
57 protected FileLock (FileChannel channel, long position, long size,
58 boolean shared)
59 {
60 if (position < 0 ||
61 size < 0)
62 throw new IllegalArgumentException ();
63
64 this.channel = channel;
65 this.position = position;
66 this.size = size;
67 this.shared = shared;
68 }
69
70 /**
71 * Tells whether or not this lock is valid.
72 */
73 public abstract boolean isValid();
74
75 /**
76 * Releases this lock.
77 *
78 * @exception IOException If an error occurs
79 * @exception ClosedChannelException If the locked channel is no longer open.
80 */
81 public abstract void release () throws IOException;
82
83 /**
84 * Returns the file channel upon whose file this lock is held.
85 */
86 public final FileChannel channel ()
87 {
88 return channel;
89 }
90
91 /**
92 * Tells whether this lock is shared.
93 */
94 public final boolean isShared ()
95 {
96 return shared;
97 }
98
99 /**
100 * Tells whether or not this lock overlaps the given lock range.
101 */
102 public final boolean overlaps (long position, long size)
103 {
104 if (position > this.position +this.size)
105 return false;
106
107 if (position + size < this.position)
108 return false;
109
110 return true;
111 }
112
113 /**
114 * Returns the position within the file of the first byte of the
115 * locked region.
116 */
117 public final long position ()
118 {
119 return position;
120 }
121
122 /**
123 * Returns the size of the locked region in bytes.
124 */
125 public final long size ()
126 {
127 return size;
128 }
129
130 /**
131 * Returns a string describing the range, type, and validity of this lock.
132 */
133 public final String toString ()
134 {
135 return "file-lock:pos=" + position + "size=" + size;
136 }
137}
Note: See TracBrowser for help on using the repository browser.