org.apache.lucene.store
Class FSDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.FSDirectory
-
- Direct Known Subclasses:
- MMapDirectory
public class FSDirectory extends Directory
Straightforward 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
-
-
Field Summary
Fields Modifier and Type Field and 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. 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)).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidclose()Closes the store to future operations.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, 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, 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()Return a string identifier that uniquely differentiates this Directory instance from other Directory instances.java.lang.String[]list()Returns an array of strings, one for each Lucene index file in the directory.IndexInputopenInput(java.lang.String name)Returns a stream reading an existing file.IndexInputopenInput(java.lang.String name, int bufferSize)Returns a stream reading an existing file, with the specified read buffer size.voidrenameFile(java.lang.String from, java.lang.String to)Deprecated.static voidsetDisableLocks(boolean doDisableLocks)Set whether Lucene's use of lock files is disabled.java.lang.StringtoString()For debug output.voidtouchFile(java.lang.String name)Set the modified time of an existing file to now.-
Methods inherited from class org.apache.lucene.store.Directory
clearLock, copy, getLockFactory, makeLock, setLockFactory
-
-
-
-
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, 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, 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.
-
fileExists
public boolean fileExists(java.lang.String name)
Returns true iff a file with the given name exists.- Specified by:
fileExistsin classDirectory
-
fileModified
public long fileModified(java.lang.String name)
Returns the time the named file was last modified.- Specified by:
fileModifiedin classDirectory
-
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.
-
fileLength
public long fileLength(java.lang.String name)
Returns the length in bytes of a file in the directory.- Specified by:
fileLengthin classDirectory
-
deleteFile
public void deleteFile(java.lang.String name) throws java.io.IOExceptionRemoves an existing file in the directory.- Specified by:
deleteFilein classDirectory- 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 classDirectory- Throws:
java.io.IOException
-
createOutput
public IndexOutput createOutput(java.lang.String name) throws java.io.IOException
Creates a new, empty file in the directory with the given name. Returns a stream writing this file.- Specified by:
createOutputin classDirectory- Throws:
java.io.IOException
-
openInput
public IndexInput openInput(java.lang.String name) throws java.io.IOException
Description copied from class:DirectoryReturns a stream reading an existing file.
-
openInput
public IndexInput openInput(java.lang.String name, int bufferSize) throws java.io.IOException
Description copied from class:DirectoryReturns a stream reading an existing file, with the specified read buffer size. The particular Directory implementation may ignore the buffer size. Currently the only Directory implementations that respect this parameter areFSDirectoryandCompoundFileReader.
-
getLockID
public java.lang.String getLockID()
Description copied from class:DirectoryReturn a string identifier that uniquely differentiates this Directory instance from other Directory instances. This ID should be the same if two Directory instances (even in different JVMs and/or on different machines) are considered "the same index". This is how locking "scopes" to the right index.
-
close
public void close()
Closes the store to future operations.
-
getFile
public java.io.File getFile()
-
toString
public java.lang.String toString()
For debug output.- Overrides:
toStringin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG