Class SimpleFSDirectory

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class SimpleFSDirectory
    extends FSDirectory
    A straightforward implementation of FSDirectory using Files.newByteChannel(Path, java.nio.file.OpenOption...). However, this class has poor concurrent performance (multiple threads will bottleneck) as it synchronizes when multiple threads read from the same file. It's usually better to use NIOFSDirectory or MMapDirectory instead.

    NOTE: Accessing this class either directly or indirectly from a thread while it's interrupted can close the underlying file descriptor immediately if at the same time the thread is blocked on IO. The file descriptor will remain closed and subsequent access to SimpleFSDirectory will throw a ClosedChannelException. If your application uses either Thread.interrupt() or Future.cancel(boolean) you should use the legacy RAFDirectory from the Lucene misc module in favor of SimpleFSDirectory.

    • Constructor Detail

      • SimpleFSDirectory

        public SimpleFSDirectory​(java.nio.file.Path path,
                                 LockFactory lockFactory)
                          throws java.io.IOException
        Create a new SimpleFSDirectory for the named location. The directory is created at the named location if it does not yet exist.
        Parameters:
        path - the path of the directory
        lockFactory - the lock factory to use
        Throws:
        java.io.IOException - if there is a low-level I/O error
      • SimpleFSDirectory

        public SimpleFSDirectory​(java.nio.file.Path path)
                          throws java.io.IOException
        Create a new SimpleFSDirectory for the named location and FSLockFactory.getDefault(). The directory is created at the named location if it does not yet exist.
        Parameters:
        path - the path of the directory
        Throws:
        java.io.IOException - if there is a low-level I/O error
    • Method Detail

      • openInput

        public IndexInput openInput​(java.lang.String name,
                                    IOContext context)
                             throws java.io.IOException
        Creates an IndexInput for the file with the given name.
        Specified by:
        openInput in class Directory
        Parameters:
        name - the name of an existing file.
        Throws:
        java.io.IOException - in case of I/O error