KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > store > Directory


1 package org.apache.lucene.store;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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 JavaDoc;
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 JavaDoc[] list()
37        throws IOException JavaDoc;
38
39   /** Returns true iff a file with the given name exists. */
40   public abstract boolean fileExists(String JavaDoc name)
41        throws IOException JavaDoc;
42
43   /** Returns the time the named file was last modified. */
44   public abstract long fileModified(String JavaDoc name)
45        throws IOException JavaDoc;
46
47   /** Set the modified time of an existing file to now. */
48   public abstract void touchFile(String JavaDoc name)
49        throws IOException JavaDoc;
50
51   /** Removes an existing file in the directory. */
52   public abstract void deleteFile(String JavaDoc name)
53        throws IOException JavaDoc;
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 JavaDoc from, String JavaDoc to)
59        throws IOException JavaDoc;
60
61   /** Returns the length of a file in the directory. */
62   public abstract long fileLength(String JavaDoc name)
63        throws IOException JavaDoc;
64
65   /** @deprecated use {@link #createOutput(String)} */
66   public OutputStream createFile(String JavaDoc name) throws IOException JavaDoc {
67     return (OutputStream)createOutput(name);
68   }
69
70   /** Creates a new, empty file in the directory with the given name.
71       Returns a stream writing this file. */

72   public IndexOutput createOutput(String JavaDoc name) throws IOException JavaDoc {
73     // default implementation for back compatibility
74
// this method should be abstract
75
return (IndexOutput)createFile(name);
76   }
77
78   /** @deprecated use {@link #openInput(String)} */
79   public InputStream openFile(String JavaDoc name) throws IOException JavaDoc {
80     return (InputStream)openInput(name);
81   }
82
83   /** Returns a stream reading an existing file. */
84   public IndexInput openInput(String JavaDoc name)
85     throws IOException JavaDoc {
86     // default implementation for back compatibility
87
// this method should be abstract
88
return (IndexInput)openFile(name);
89   }
90
91   /** Construct a {@link Lock}.
92    * @param name the name of the lock file
93    */

94   public abstract Lock makeLock(String JavaDoc name);
95
96   /** Closes the store. */
97   public abstract void close()
98        throws IOException JavaDoc;
99 }
100
Popular Tags