public abstract class Directory
extends java.lang.Object
implements java.io.Closeable
Java's i/o APIs not used directly, but rather all i/o is through this API. This permits things such as:
LockFactory, and can be changed for each Directory
instance using setLockFactory(org.apache.lucene.store.LockFactory).| Modifier and Type | Class and Description |
|---|---|
class |
Directory.IndexInputSlicer
Allows to create one or more sliced
IndexInput instances from a single
file handle. |
| Constructor and Description |
|---|
Directory() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
clearLock(java.lang.String name)
Attempt to clear (forcefully unlock and remove) the
specified lock.
|
abstract void |
close()
Closes the store.
|
void |
copy(Directory to,
java.lang.String src,
java.lang.String dest,
IOContext context)
Copies the file src to
Directory to under the new
file name dest. |
abstract IndexOutput |
createOutput(java.lang.String name,
IOContext context)
Creates a new, empty file in the directory with the given name.
|
Directory.IndexInputSlicer |
createSlicer(java.lang.String name,
IOContext context)
Creates an
Directory.IndexInputSlicer for the given file name. |
abstract void |
deleteFile(java.lang.String name)
Removes an existing file in the directory.
|
abstract boolean |
fileExists(java.lang.String name)
Returns true iff a file with the given name exists.
|
abstract long |
fileLength(java.lang.String name)
Returns the length of a file in the directory.
|
abstract LockFactory |
getLockFactory()
Get the LockFactory that this Directory instance is
using for its locking implementation.
|
java.lang.String |
getLockID()
Return a string identifier that uniquely differentiates
this Directory instance from other Directory instances.
|
abstract java.lang.String[] |
listAll()
Returns an array of strings, one for each file in the directory.
|
abstract Lock |
makeLock(java.lang.String name)
Construct a
Lock. |
abstract IndexInput |
openInput(java.lang.String name,
IOContext context)
Returns a stream reading an existing file, with the
specified read buffer size.
|
abstract void |
setLockFactory(LockFactory lockFactory)
Set the LockFactory that this Directory instance should
use for its locking implementation.
|
abstract void |
sync(java.util.Collection<java.lang.String> names)
Ensure that any writes to these files are moved to
stable storage.
|
java.lang.String |
toString() |
public abstract java.lang.String[] listAll()
throws java.io.IOException
NoSuchDirectoryException - if the directory is not prepared for any
write operations (such as createOutput(String, IOContext)).java.io.IOException - in case of other IO errorspublic abstract boolean fileExists(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic abstract void deleteFile(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic abstract long fileLength(java.lang.String name)
throws java.io.IOException
FileNotFoundException if the file does not exist
(not java.nio.file.NoSuchFileException of Java 7).
name - the name of the file for which to return the length.java.io.IOException - if there was an IO error while retrieving the file's
length.public abstract IndexOutput createOutput(java.lang.String name, IOContext context) throws java.io.IOException
java.io.IOExceptionpublic abstract void sync(java.util.Collection<java.lang.String> names)
throws java.io.IOException
java.io.IOExceptionpublic abstract IndexInput openInput(java.lang.String name, IOContext context) throws java.io.IOException
FSDirectory and CompoundFileDirectory.
FileNotFoundException if the file does not exist
(not java.nio.file.NoSuchFileException of Java 7).java.io.IOExceptionpublic abstract Lock makeLock(java.lang.String name)
Lock.name - the name of the lock filepublic abstract void clearLock(java.lang.String name)
throws java.io.IOException
name - name of the lock to be cleared.java.io.IOExceptionpublic abstract void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic abstract void setLockFactory(LockFactory lockFactory) throws java.io.IOException
lockFactory - instance of LockFactory.java.io.IOExceptionpublic abstract LockFactory getLockFactory()
public java.lang.String getLockID()
public java.lang.String toString()
toString in class java.lang.Objectpublic void copy(Directory to, java.lang.String src, java.lang.String dest, IOContext context) throws java.io.IOException
Directory to under the new
file name dest.
If you want to copy the entire source directory to the destination one, you can do so like this:
Directory to; // the directory to copy to
for (String file : dir.listAll()) {
dir.copy(to, file, newFile, IOContext.DEFAULT); // newFile can be either file, or a new name
}
NOTE: this method does not check whether dest exist and will overwrite it if it does.
java.io.IOExceptionpublic Directory.IndexInputSlicer createSlicer(java.lang.String name, IOContext context) throws java.io.IOException
Directory.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.
FileNotFoundException if the file does not exist
(not java.nio.file.NoSuchFileException of Java 7).java.io.IOException - if an IOException occursCopyright © 2010 - 2024 Adobe. All Rights Reserved