org.apache.lucene.store

Class FSDirectory

public final class FSDirectory extends Directory

Straightforward implementation of {@link Directory} as a directory of files.

If the system property 'disableLuceneLocks' has the String value of "true", lock creation will be disabled.

Author: Doug Cutting

See Also: Directory

Field Summary
static StringLOCK_DIR
Directory specified by org.apache.lucene.lockdir or java.io.tmpdir system property
Method Summary
voidclose()
Closes the store to future operations.
OutputStreamcreateFile(String name)
Creates a new, empty file in the directory with the given name.
voiddeleteFile(String name)
Removes an existing file in the directory.
booleanfileExists(String name)
Returns true iff a file with the given name exists.
longfileLength(String name)
Returns the length in bytes of a file in the directory.
longfileModified(String name)
Returns the time the named file was last modified.
static longfileModified(File directory, String name)
Returns the time the named file was last modified.
static FSDirectorygetDirectory(String path, boolean create)
Returns the directory instance for the named location.
static FSDirectorygetDirectory(File file, boolean create)
Returns the directory instance for the named location.
FilegetFile()
String[]list()
Returns an array of strings, one for each file in the directory.
LockmakeLock(String name)
Constructs a {@link Lock} with the specified name.
InputStreamopenFile(String name)
Returns a stream reading an existing file.
voidrenameFile(String from, String to)
Renames an existing file in the directory.
StringtoString()
For debug output.
voidtouchFile(String name)
Set the modified time of an existing file to now.

Field Detail

LOCK_DIR

public static final String LOCK_DIR
Directory specified by org.apache.lucene.lockdir or java.io.tmpdir system property

Method Detail

close

public final void close()
Closes the store to future operations.

createFile

public final OutputStream createFile(String name)
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.

deleteFile

public final void deleteFile(String name)
Removes an existing file in the directory.

fileExists

public final boolean fileExists(String name)
Returns true iff a file with the given name exists.

fileLength

public final long fileLength(String name)
Returns the length in bytes of a file in the directory.

fileModified

public final long fileModified(String name)
Returns the time the named file was last modified.

fileModified

public static final long fileModified(File directory, String name)
Returns the time the named file was last modified.

getDirectory

public static FSDirectory getDirectory(String path, boolean create)
Returns the directory instance for the named location.

Directories are cached, so that, for a given canonical path, the same FSDirectory instance will always be returned. This permits synchronization on directories.

Parameters: path the path to the directory. create if true, create, or erase any existing contents.

Returns: the FSDirectory for the named file.

getDirectory

public static FSDirectory getDirectory(File file, boolean create)
Returns the directory instance for the named location.

Directories are cached, so that, for a given canonical path, the same FSDirectory instance will always be returned. This permits synchronization on directories.

Parameters: file the path to the directory. create if true, create, or erase any existing contents.

Returns: the FSDirectory for the named file.

getFile

public File getFile()

list

public final String[] list()
Returns an array of strings, one for each file in the directory.

makeLock

public final Lock makeLock(String name)
Constructs a {@link Lock} with the specified name. Locks are implemented with {@link File#createNewFile() }.

In JDK 1.1 or if system property disableLuceneLocks is the string "true", locks are disabled. Assigning this property any other string will not prevent creation of lock files. This is useful for using Lucene on read-only medium, such as CD-ROM.

Parameters: name the name of the lock file

Returns: an instance of Lock holding the lock

openFile

public final InputStream openFile(String name)
Returns a stream reading an existing file.

renameFile

public final void renameFile(String from, String to)
Renames an existing file in the directory.

toString

public String toString()
For debug output.

touchFile

public void touchFile(String name)
Set the modified time of an existing file to now.
Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.