Package org.apache.lucene.store
Class FilterDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.FilterDirectory
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
RateLimitedDirectoryWrapper,TrackingDirectoryWrapper
public class FilterDirectory extends Directory
Directory implementation that delegates calls to another directory. This class can be used to add limitations on top of an existingDirectoryimplementation such asrate limitingor to add additional sanity checks for tests. However, if you plan to write your ownDirectoryimplementation, you should consider extending directlyDirectoryorBaseDirectoryrather than try to reuse functionality of existingDirectorys by extending this class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.store.Directory
Directory.IndexInputSlicer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearLock(java.lang.String name)Attempt to clear (forcefully unlock and remove) the specified lock.voidclose()Closes the store.IndexOutputcreateOutput(java.lang.String name, IOContext context)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 of a file in the directory.DirectorygetDelegate()Return the wrappedDirectory.LockFactorygetLockFactory()Get the LockFactory that this Directory instance is using for its locking implementation.java.lang.StringgetLockID()Return a string identifier that uniquely differentiates this Directory instance from other Directory instances.java.lang.String[]listAll()Returns an array of strings, one for each file in the directory.LockmakeLock(java.lang.String name)Construct aLock.IndexInputopenInput(java.lang.String name, IOContext context)Returns a stream reading an existing file, with the specified read buffer size.voidsetLockFactory(LockFactory lockFactory)Set the LockFactory that this Directory instance should use for its locking implementation.voidsync(java.util.Collection<java.lang.String> names)Ensure that any writes to these files are moved to stable storage.java.lang.StringtoString()-
Methods inherited from class org.apache.lucene.store.Directory
copy, createSlicer
-
-
-
-
Method Detail
-
listAll
public java.lang.String[] listAll() throws java.io.IOExceptionDescription copied from class:DirectoryReturns an array of strings, one for each file in the directory.- Specified by:
listAllin classDirectory- Throws:
NoSuchDirectoryException- if the directory is not prepared for any write operations (such asDirectory.createOutput(String, IOContext)).java.io.IOException- in case of other IO errors
-
fileExists
public boolean fileExists(java.lang.String name) throws java.io.IOExceptionDescription copied from class:DirectoryReturns true iff a file with the given name exists.- Specified by:
fileExistsin classDirectory- Throws:
java.io.IOException
-
deleteFile
public void deleteFile(java.lang.String name) throws java.io.IOExceptionDescription copied from class:DirectoryRemoves an existing file in the directory.- Specified by:
deleteFilein classDirectory- Throws:
java.io.IOException
-
fileLength
public long fileLength(java.lang.String name) throws java.io.IOExceptionDescription copied from class:DirectoryReturns the length of a file in the directory. This method follows the following contract:- Must throw
FileNotFoundExceptionif the file does not exist (notjava.nio.file.NoSuchFileExceptionof Java 7). - Returns a value ≥0 if the file exists, which specifies its length.
- Specified by:
fileLengthin classDirectory- Parameters:
name- the name of the file for which to return the length.- Throws:
java.io.IOException- if there was an IO error while retrieving the file's length.
- Must throw
-
createOutput
public IndexOutput createOutput(java.lang.String name, IOContext context) throws java.io.IOException
Description copied from class:DirectoryCreates 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
-
sync
public void sync(java.util.Collection<java.lang.String> names) throws java.io.IOExceptionDescription copied from class:DirectoryEnsure that any writes to these files are moved to stable storage. Lucene uses this to properly commit changes to the index, to prevent a machine/OS crash from corrupting the index.
NOTE: Clients may call this method for same files over and over again, so some impls might optimize for that. For other impls the operation can be a noop, for various reasons.
-
openInput
public IndexInput openInput(java.lang.String name, IOContext context) 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 areFSDirectoryandCompoundFileDirectory.- Must throw
FileNotFoundExceptionif the file does not exist (notjava.nio.file.NoSuchFileExceptionof Java 7). - Must throw
-
makeLock
public Lock makeLock(java.lang.String name)
Description copied from class:DirectoryConstruct aLock.
-
clearLock
public void clearLock(java.lang.String name) throws java.io.IOExceptionDescription copied from class:DirectoryAttempt to clear (forcefully unlock and remove) the specified lock. Only call this at a time when you are certain this lock is no longer in use.
-
close
public void close() throws java.io.IOExceptionDescription copied from class:DirectoryCloses the store.
-
setLockFactory
public void setLockFactory(LockFactory lockFactory) throws java.io.IOException
Description copied from class:DirectorySet the LockFactory that this Directory instance should use for its locking implementation. Each * instance of LockFactory should only be used for one directory (ie, do not share a single instance across multiple Directories).- Specified by:
setLockFactoryin classDirectory- Parameters:
lockFactory- instance ofLockFactory.- Throws:
java.io.IOException
-
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.
-
getLockFactory
public LockFactory getLockFactory()
Description copied from class:DirectoryGet the LockFactory that this Directory instance is using for its locking implementation. Note that this may be null for Directory implementations that provide their own locking implementation.- Specified by:
getLockFactoryin classDirectory
-
-