Class FSDirectory

  • Direct Known Subclasses:
    AlfrescoFSDirectory

    public class FSDirectory
    extends org.apache.lucene.store.Directory
    Straightforward implementation of Directory as a directory of files. Locking implementation is by default the SimpleFSLockFactory, but can be changed either by passing in a LockFactory instance to getDirectory, or specifying the LockFactory class by setting org.apache.lucene.store.FSDirectoryLockFactoryClass Java system property, or by calling Directory.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 Description
      static java.lang.String LOCK_DIR
      Deprecated.
      As of 2.1, LOCK_DIR is unused because the write.lock is now stored by default in the index directory.
      • Fields inherited from class org.apache.lucene.store.Directory

        lockFactory
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected FSDirectory()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void close()
      Closes the store to future operations.
      org.apache.lucene.store.IndexOutput createOutput​(java.lang.String name)
      Creates a new, empty file in the directory with the given name.
      void deleteFile​(java.lang.String name)
      Removes an existing file in the directory.
      boolean fileExists​(java.lang.String name)
      Returns true iff a file with the given name exists.
      long fileLength​(java.lang.String name)
      Returns the length in bytes of a file in the directory.
      static long fileModified​(java.io.File directory, java.lang.String name)
      Returns the time the named file was last modified.
      long fileModified​(java.lang.String name)
      Returns the time the named file was last modified.
      static FSDirectory getDirectory​(java.io.File file)
      Returns the directory instance for the named location.
      static FSDirectory getDirectory​(java.io.File file, boolean create)
      Deprecated.
      Use IndexWriter's create flag, instead, to create a new index.
      static FSDirectory getDirectory​(java.io.File file, org.apache.lucene.store.LockFactory lockFactory)
      Returns the directory instance for the named location.
      static FSDirectory getDirectory​(java.lang.String path)
      Returns the directory instance for the named location.
      static FSDirectory getDirectory​(java.lang.String path, boolean create)
      Deprecated.
      Use IndexWriter's create flag, instead, to create a new index.
      static FSDirectory getDirectory​(java.lang.String path, org.apache.lucene.store.LockFactory lockFactory)
      Returns the directory instance for the named location.
      static boolean getDisableLocks()
      Returns whether Lucene's use of lock files is disabled.
      java.io.File getFile()  
      java.lang.String getLockID()  
      java.lang.String[] list()
      Returns an array of strings, one for each Lucene index file in the directory.
      org.apache.lucene.store.IndexInput openInput​(java.lang.String name)  
      org.apache.lucene.store.IndexInput openInput​(java.lang.String name, int bufferSize)  
      void renameFile​(java.lang.String from, java.lang.String to)
      Deprecated. 
      static void setDisableLocks​(boolean doDisableLocks)
      Set whether Lucene's use of lock files is disabled.
      void sync​(java.lang.String name)  
      java.lang.String toString()
      For debug output.
      void touchFile​(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, ensureOpen, getLockFactory, makeLock, setLockFactory
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LOCK_DIR

        public static final java.lang.String LOCK_DIR
        Deprecated.
        As of 2.1, LOCK_DIR is 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 own SimpleFSLockFactory (or NativeFSLockFactory, etc.) passing in your preferred lock directory. Then, pass this LockFactory instance to one of the getDirectory methods that take a lockFactory (for example, getDirectory(String, LockFactory)).
        Directory specified by org.apache.lucene.lockDir or java.io.tmpdir system property.
    • Constructor Detail

      • FSDirectory

        protected FSDirectory()
    • 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 of LockFactory providing 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 of LockFactory providing 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:
        list in class org.apache.lucene.store.Directory
      • fileExists

        public boolean fileExists​(java.lang.String name)
        Returns true iff a file with the given name exists.
        Specified by:
        fileExists in class org.apache.lucene.store.Directory
      • fileModified

        public long fileModified​(java.lang.String name)
        Returns the time the named file was last modified.
        Specified by:
        fileModified in class org.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:
        touchFile in class org.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:
        fileLength in class org.apache.lucene.store.Directory
      • deleteFile

        public void deleteFile​(java.lang.String name)
                        throws java.io.IOException
        Removes an existing file in the directory.
        Specified by:
        deleteFile in class org.apache.lucene.store.Directory
        Throws:
        java.io.IOException
      • renameFile

        public void renameFile​(java.lang.String from,
                               java.lang.String to)
                        throws java.io.IOException
        Deprecated.
        Renames an existing file in the directory. Warning: This is not atomic.
        Specified by:
        renameFile in class org.apache.lucene.store.Directory
        Throws:
        java.io.IOException
      • createOutput

        public org.apache.lucene.store.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:
        createOutput in class org.apache.lucene.store.Directory
        Throws:
        java.io.IOException
      • sync

        public void sync​(java.lang.String name)
                  throws java.io.IOException
        Overrides:
        sync in class org.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:
        openInput in class org.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:
        openInput in class org.apache.lucene.store.Directory
        Throws:
        java.io.IOException
      • getLockID

        public java.lang.String getLockID()
        Overrides:
        getLockID in class org.apache.lucene.store.Directory
      • close

        public void close()
        Closes the store to future operations.
        Specified by:
        close in class org.apache.lucene.store.Directory
      • getFile

        public java.io.File getFile()
      • toString

        public java.lang.String toString()
        For debug output.
        Overrides:
        toString in class java.lang.Object