Directory.java
01 package gate.creole.annic.apache.lucene.store;
02 
03 /**
04  * Copyright 2004 The Apache Software Foundation
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 import java.io.IOException;
20 
21 /** A Directory is a flat list of files.  Files may be written once, when they
22  * are created.  Once a file is created it may only be opened for read, or
23  * deleted.  Random access is permitted both when reading and writing.
24  *
25  <p> Java's i/o APIs not used directly, but rather all i/o is
26  * through this API.  This permits things such as: <ul>
27  <li> implementation of RAM-based indices;
28  <li> implementation indices stored in a database, via JDBC;
29  <li> implementation of an index as a single file;
30  </ul>
31  *
32  @author Doug Cutting
33  */
34 public abstract class Directory {
35   /** Returns an array of strings, one for each file in the directory. */
36   public abstract String[] list()
37        throws IOException;
38 
39   /** Returns true iff a file with the given name exists. */
40   public abstract boolean fileExists(String name)
41        throws IOException;
42 
43   /** Returns the time the named file was last modified. */
44   public abstract long fileModified(String name)
45        throws IOException;
46 
47   /** Set the modified time of an existing file to now. */
48   public abstract void touchFile(String name)
49        throws IOException;
50 
51   /** Removes an existing file in the directory. */
52   public abstract void deleteFile(String name)
53        throws IOException;
54 
55   /** Renames an existing file in the directory.
56     If a file already exists with the new name, then it is replaced.
57     This replacement should be atomic. */
58   public abstract void renameFile(String from, String to)
59        throws IOException;
60 
61   /** Returns the length of a file in the directory. */
62   public abstract long fileLength(String name)
63        throws IOException;
64 
65   /** Creates a new, empty file in the directory with the given name.
66       Returns a stream writing this file. */
67   public abstract OutputStream createFile(String name)
68        throws IOException;
69 
70   /** Returns a stream reading an existing file. */
71   public abstract InputStream openFile(String name)
72        throws IOException;
73 
74   /** Construct a {@link Lock}.
75    @param name the name of the lock file
76    */
77   public abstract Lock makeLock(String name);
78 
79   /** Closes the store. */
80   public abstract void close()
81        throws IOException;
82 }