public class NIOFSDirectory extends FSDirectory
FSDirectory
implementation that uses java.nio's FileChannel's
positional read, which allows multiple threads to read from the same file
without synchronizing.
This class only uses FileChannel when reading; writing is achieved with
FSDirectory.FSIndexOutput
.
NOTE: NIOFSDirectory is not recommended on Windows because of a bug in how FileChannel.read is implemented in Sun's JRE. Inside of the implementation the position is apparently synchronized. See here for details.
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 NIOFSDirectory
will throw a ClosedChannelException
. If
your application uses either Thread.interrupt()
or
Future.cancel(boolean)
you should use SimpleFSDirectory
in
favor of NIOFSDirectory
.
Modifier and Type | Class and Description |
---|---|
protected static class |
NIOFSDirectory.NIOFSIndexInput |
FSDirectory.FSIndexOutput
DEFAULT_READ_CHUNK_SIZE, directory, staleFiles
isOpen, lockFactory
Constructor and Description |
---|
NIOFSDirectory(File path)
Create a new NIOFSDirectory for the named location and
NativeFSLockFactory . |
NIOFSDirectory(File path,
LockFactory lockFactory)
Create a new NIOFSDirectory for the named location.
|
Modifier and Type | Method and Description |
---|---|
IndexInput |
openInput(String name,
int bufferSize)
Creates an IndexInput for the file with the given name.
|
close, createOutput, deleteFile, ensureCanWrite, fileExists, fileLength, fileModified, fileModified, fsync, getDirectory, getFile, getLockID, getReadChunkSize, listAll, listAll, onIndexOutputClosed, open, open, openInput, setLockFactory, setReadChunkSize, sync, sync, toString, touchFile
clearLock, copy, copy, ensureOpen, getLockFactory, makeLock
public NIOFSDirectory(File path, LockFactory lockFactory) throws IOException
path
- the path of the directorylockFactory
- the lock factory to use, or null for the default
(NativeFSLockFactory
);IOException
public NIOFSDirectory(File path) throws IOException
NativeFSLockFactory
.path
- the path of the directoryIOException
public IndexInput openInput(String name, int bufferSize) throws IOException
openInput
in class Directory
IOException