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
Reads bytes with
FileChannel.read(ByteBuffer, long) |
FSDirectory.FSIndexInput, FSDirectory.FSIndexOutputDirectory.IndexInputSlicerDEFAULT_READ_CHUNK_SIZE, directory, staleFilesisOpen, 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 |
|---|---|
Directory.IndexInputSlicer |
createSlicer(String name,
IOContext context)
Creates an
Directory.IndexInputSlicer for the given file name. |
IndexInput |
openInput(String name,
IOContext context)
Creates an IndexInput for the file with the given name.
|
close, createOutput, deleteFile, ensureCanWrite, fileExists, fileLength, fileModified, fsync, getDirectory, getLockID, getMaxMergeWriteMBPerSec, getReadChunkSize, listAll, listAll, onIndexOutputClosed, open, open, setLockFactory, setMaxMergeWriteLimiter, setMaxMergeWriteMBPerSec, setReadChunkSize, sync, toStringclearLock, copy, ensureOpen, getLockFactory, makeLockpublic 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 - if there is a low-level I/O errorpublic NIOFSDirectory(File path) throws IOException
NativeFSLockFactory.path - the path of the directoryIOException - if there is a low-level I/O errorpublic IndexInput openInput(String name, IOContext context) throws IOException
openInput in class DirectoryIOExceptionpublic Directory.IndexInputSlicer createSlicer(String name, IOContext context) throws IOException
DirectoryDirectory.IndexInputSlicer for the given file name.
IndexInputSlicer allows other Directory implementations to
efficiently open one or more sliced IndexInput instances from a
single file handle. The underlying file handle is kept open until the
Directory.IndexInputSlicer is closed.createSlicer in class DirectoryIOException - if an IOException occursCopyright © 2000-2012 Apache Software Foundation. All Rights Reserved.