Package org.apache.lucene.store
Class FSDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.FSDirectory
-
- Direct Known Subclasses:
AlfrescoFSDirectory
public class FSDirectory extends org.apache.lucene.store.DirectoryStraightforward implementation ofDirectoryas a directory of files. Locking implementation is by default theSimpleFSLockFactory, but can be changed either by passing in aLockFactoryinstance togetDirectory, or specifying the LockFactory class by settingorg.apache.lucene.store.FSDirectoryLockFactoryClassJava system property, or by callingDirectory.setLockFactory(org.apache.lucene.store.LockFactory)after creating the Directory.Directories are cached, so that, for a given canonical path, the same FSDirectory instance will always be returned by
getDirectory. This permits synchronization on directories.- See Also:
Directory
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classFSDirectory.FSIndexInputprotected static classFSDirectory.FSIndexOutput
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringLOCK_DIRDeprecated.As of 2.1,LOCK_DIRis unused because the write.lock is now stored by default in the index directory.
-
Constructor Summary
Constructors Modifier Constructor Description protectedFSDirectory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidclose()Closes the store to future operations.org.apache.lucene.store.IndexOutputcreateOutput(java.lang.String name)Creates a new, empty file in the directory with the given name.voiddeleteFile(java.lang.String name)Removes an existing file in the directory.booleanfileExists(java.lang.String name)Returns true iff a file with the given name exists.longfileLength(java.lang.String name)Returns the length in bytes of a file in the directory.static longfileModified(java.io.File directory, java.lang.String name)Returns the time the named file was last modified.longfileModified(java.lang.String name)Returns the time the named file was last modified.static FSDirectorygetDirectory(java.io.File file)Returns the directory instance for the named location.static FSDirectorygetDirectory(java.io.File file, boolean create)Deprecated.Use IndexWriter's create flag, instead, to create a new index.static FSDirectorygetDirectory(java.io.File file, org.apache.lucene.store.LockFactory lockFactory)Returns the directory instance for the named location.static FSDirectorygetDirectory(java.lang.String path)Returns the directory instance for the named location.static FSDirectorygetDirectory(java.lang.String path, boolean create)Deprecated.Use IndexWriter's create flag, instead, to create a new index.static FSDirectorygetDirectory(java.lang.String path, org.apache.lucene.store.LockFactory lockFactory)Returns the directory instance for the named location.static booleangetDisableLocks()Returns whether Lucene's use of lock files is disabled.java.io.FilegetFile()java.lang.StringgetLockID()java.lang.String[]list()Returns an array of strings, one for each Lucene index file in the directory.org.apache.lucene.store.IndexInputopenInput(java.lang.String name)org.apache.lucene.store.IndexInputopenInput(java.lang.String name, int bufferSize)voidrenameFile(java.lang.String from, java.lang.String to)Deprecated.static voidsetDisableLocks(boolean doDisableLocks)Set whether Lucene's use of lock files is disabled.voidsync(java.lang.String name)java.lang.StringtoString()For debug output.voidtouchFile(java.lang.String name)Set the modified time of an existing file to now.
-
-
-
Field Detail
-
LOCK_DIR
public static final java.lang.String LOCK_DIR
Deprecated.As of 2.1,LOCK_DIRis unused because the write.lock is now stored by default in the index directory. If you really want to store locks elsewhere you can create your ownSimpleFSLockFactory(orNativeFSLockFactory, etc.) passing in your preferred lock directory. Then, pass thisLockFactoryinstance to one of thegetDirectorymethods that take alockFactory(for example,getDirectory(String, LockFactory)).Directory specified byorg.apache.lucene.lockDirorjava.io.tmpdirsystem property.
-
-
Method Detail
-
setDisableLocks
public static void setDisableLocks(boolean doDisableLocks)
Set whether Lucene's use of lock files is disabled. By default, lock files are enabled. They should only be disabled if the index is on a read-only medium like a CD-ROM.
-
getDisableLocks
public static boolean getDisableLocks()
Returns whether Lucene's use of lock files is disabled.- Returns:
- true if locks are disabled, false if locks are enabled.
-
getDirectory
public static FSDirectory getDirectory(java.lang.String path) throws java.io.IOException
Returns the directory instance for the named location.- Parameters:
path- the path to the directory.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
getDirectory
public static FSDirectory getDirectory(java.lang.String path, org.apache.lucene.store.LockFactory lockFactory) throws java.io.IOException
Returns the directory instance for the named location.- Parameters:
path- the path to the directory.lockFactory- instance ofLockFactoryproviding the locking implementation.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
getDirectory
public static FSDirectory getDirectory(java.io.File file) throws java.io.IOException
Returns the directory instance for the named location.- Parameters:
file- the path to the directory.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
getDirectory
public static FSDirectory getDirectory(java.io.File file, org.apache.lucene.store.LockFactory lockFactory) throws java.io.IOException
Returns the directory instance for the named location.- Parameters:
file- the path to the directory.lockFactory- instance ofLockFactoryproviding the locking implementation.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
getDirectory
public static FSDirectory getDirectory(java.lang.String path, boolean create) throws java.io.IOException
Deprecated.Use IndexWriter's create flag, instead, to create a new index.Returns the directory instance for the named location.- Parameters:
path- the path to the directory.create- if true, create, or erase any existing contents.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
getDirectory
public static FSDirectory getDirectory(java.io.File file, boolean create) throws java.io.IOException
Deprecated.Use IndexWriter's create flag, instead, to create a new index.Returns the directory instance for the named location.- Parameters:
file- the path to the directory.create- if true, create, or erase any existing contents.- Returns:
- the FSDirectory for the named file.
- Throws:
java.io.IOException
-
list
public java.lang.String[] list()
Returns an array of strings, one for each Lucene index file in the directory.- Specified by:
listin classorg.apache.lucene.store.Directory
-
fileExists
public boolean fileExists(java.lang.String name)
Returns true iff a file with the given name exists.- Specified by:
fileExistsin classorg.apache.lucene.store.Directory
-
fileModified
public long fileModified(java.lang.String name)
Returns the time the named file was last modified.- Specified by:
fileModifiedin classorg.apache.lucene.store.Directory
-
fileModified
public static long fileModified(java.io.File directory, java.lang.String name)Returns the time the named file was last modified.
-
touchFile
public void touchFile(java.lang.String name)
Set the modified time of an existing file to now.- Specified by:
touchFilein classorg.apache.lucene.store.Directory
-
fileLength
public long fileLength(java.lang.String name)
Returns the length in bytes of a file in the directory.- Specified by:
fileLengthin classorg.apache.lucene.store.Directory
-
deleteFile
public void deleteFile(java.lang.String name) throws java.io.IOExceptionRemoves an existing file in the directory.- Specified by:
deleteFilein classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
renameFile
public void renameFile(java.lang.String from, java.lang.String to) throws java.io.IOExceptionDeprecated.Renames an existing file in the directory. Warning: This is not atomic.- Specified by:
renameFilein classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
createOutput
public org.apache.lucene.store.IndexOutput createOutput(java.lang.String name) throws java.io.IOExceptionCreates a new, empty file in the directory with the given name. Returns a stream writing this file.- Specified by:
createOutputin classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
sync
public void sync(java.lang.String name) throws java.io.IOException- Overrides:
syncin classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
openInput
public org.apache.lucene.store.IndexInput openInput(java.lang.String name) throws java.io.IOException- Specified by:
openInputin classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
openInput
public org.apache.lucene.store.IndexInput openInput(java.lang.String name, int bufferSize) throws java.io.IOException- Overrides:
openInputin classorg.apache.lucene.store.Directory- Throws:
java.io.IOException
-
getLockID
public java.lang.String getLockID()
- Overrides:
getLockIDin classorg.apache.lucene.store.Directory
-
close
public void close()
Closes the store to future operations.- Specified by:
closein classorg.apache.lucene.store.Directory
-
getFile
public java.io.File getFile()
-
toString
public java.lang.String toString()
For debug output.- Overrides:
toStringin classjava.lang.Object
-
-