org.apache.lucene.store
Class RAMDirectory
- java.lang.Object
-
- org.apache.lucene.store.Directory
-
- org.apache.lucene.store.RAMDirectory
-
- All Implemented Interfaces:
- java.io.Serializable
public class RAMDirectory extends Directory implements java.io.Serializable
A memory-residentDirectoryimplementation. Locking implementation is by default theSingleInstanceLockFactorybut can be changed withDirectory.setLockFactory(org.apache.lucene.store.LockFactory).- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description RAMDirectory()Constructs an emptyDirectory.RAMDirectory(Directory dir)Creates a newRAMDirectoryinstance from a differentDirectoryimplementation.RAMDirectory(java.io.File dir)Creates a newRAMDirectoryinstance from theFSDirectory.RAMDirectory(java.lang.String dir)Creates a newRAMDirectoryinstance from theFSDirectory.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidclose()Closes the store to future operations, releasing associated memory.IndexOutputcreateOutput(java.lang.String name)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 the named file exists in this directory.longfileLength(java.lang.String name)Returns the length in bytes of a file in the directory.longfileModified(java.lang.String name)Returns the time the named file was last modified.java.lang.String[]list()Returns an array of strings, one for each file in the directory.IndexInputopenInput(java.lang.String name)Returns a stream reading an existing file.voidrenameFile(java.lang.String from, java.lang.String to)Deprecated.longsizeInBytes()Return total size in bytes of all files in this directory.voidtouchFile(java.lang.String name)Set the modified time of an existing file to now.-
Methods inherited from class org.apache.lucene.store.Directory
clearLock, copy, getLockFactory, getLockID, makeLock, openInput, setLockFactory
-
-
-
-
Constructor Detail
-
RAMDirectory
public RAMDirectory()
Constructs an emptyDirectory.
-
RAMDirectory
public RAMDirectory(Directory dir) throws java.io.IOException
Creates a newRAMDirectoryinstance from a differentDirectoryimplementation. This can be used to load a disk-based index into memory.This should be used only with indices that can fit into memory.
Note that the resulting
RAMDirectoryinstance is fully independent from the originalDirectory(it is a complete copy). Any subsequent changes to the originalDirectorywill not be visible in theRAMDirectoryinstance.- Parameters:
dir- aDirectoryvalue- Throws:
java.io.IOException- if an error occurs
-
RAMDirectory
public RAMDirectory(java.io.File dir) throws java.io.IOExceptionCreates a newRAMDirectoryinstance from theFSDirectory.- Parameters:
dir- aFilespecifying the index directory- Throws:
java.io.IOException- See Also:
RAMDirectory(Directory)
-
RAMDirectory
public RAMDirectory(java.lang.String dir) throws java.io.IOExceptionCreates a newRAMDirectoryinstance from theFSDirectory.- Parameters:
dir- aStringspecifying the full index directory path- Throws:
java.io.IOException- See Also:
RAMDirectory(Directory)
-
-
Method Detail
-
list
public final java.lang.String[] list()
Returns an array of strings, one for each file in the directory.
-
fileExists
public final boolean fileExists(java.lang.String name)
Returns true iff the named file exists in this directory.- Specified by:
fileExistsin classDirectory
-
fileModified
public final long fileModified(java.lang.String name) throws java.io.IOExceptionReturns the time the named file was last modified.- Specified by:
fileModifiedin classDirectory- Throws:
java.io.IOException- if the file does not exist
-
touchFile
public void touchFile(java.lang.String name) throws java.io.IOExceptionSet the modified time of an existing file to now.
-
fileLength
public final long fileLength(java.lang.String name) throws java.io.IOExceptionReturns the length in bytes of a file in the directory.- Specified by:
fileLengthin classDirectory- Throws:
java.io.IOException- if the file does not exist
-
sizeInBytes
public final long sizeInBytes()
Return total size in bytes of all files in this directory. This is currently quantized to RAMOutputStream.BUFFER_SIZE.
-
deleteFile
public void deleteFile(java.lang.String name) throws java.io.IOExceptionRemoves an existing file in the directory.- Specified by:
deleteFilein classDirectory- Throws:
java.io.IOException- if the file does not exist
-
renameFile
public final void renameFile(java.lang.String from, java.lang.String to) throws java.io.IOExceptionDeprecated.Renames an existing file in the directory.- Specified by:
renameFilein classDirectory- Throws:
java.io.FileNotFoundException- if from does not existjava.io.IOException
-
createOutput
public IndexOutput createOutput(java.lang.String name) throws java.io.IOException
Creates 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
-
openInput
public IndexInput openInput(java.lang.String name) throws java.io.IOException
Returns a stream reading an existing file.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG