Constructors Summary |
---|
public RAMDirectory()Constructs an empty {@link Directory}.
// *****
// Lock acquisition sequence: RAMDirectory, then RAMFile
// *****
setLockFactory(new SingleInstanceLockFactory());
|
public RAMDirectory(Directory dir)Creates a new RAMDirectory instance from a different
Directory implementation. 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 RAMDirectory instance is fully
independent from the original Directory (it is a
complete copy). Any subsequent changes to the
original Directory will not be visible in the
RAMDirectory instance.
this(dir, false);
|
private RAMDirectory(Directory dir, boolean closeDir)
this();
Directory.copy(dir, this, closeDir);
|
public RAMDirectory(File dir)Creates a new RAMDirectory instance from the {@link FSDirectory}.
this(FSDirectory.getDirectory(dir), true);
|
public RAMDirectory(String dir)Creates a new RAMDirectory instance from the {@link FSDirectory}.
this(FSDirectory.getDirectory(dir), true);
|
Methods Summary |
---|
public final void | close()Closes the store to future operations, releasing associated memory.
fileMap = null;
|
public org.apache.lucene.store.IndexOutput | createOutput(java.lang.String name)Creates a new, empty file in the directory with the given name. Returns a stream writing this file.
RAMFile file = new RAMFile(this);
synchronized (this) {
RAMFile existing = (RAMFile)fileMap.get(name);
if (existing!=null) {
sizeInBytes -= existing.sizeInBytes;
existing.directory = null;
}
fileMap.put(name, file);
}
return new RAMOutputStream(file);
|
public final synchronized void | deleteFile(java.lang.String name)Removes an existing file in the directory.
RAMFile file = (RAMFile)fileMap.get(name);
if (file!=null) {
fileMap.remove(name);
file.directory = null;
sizeInBytes -= file.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory
} else
throw new FileNotFoundException(name);
|
public final boolean | fileExists(java.lang.String name)Returns true iff the named file exists in this directory.
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
return file != null;
|
public final long | fileLength(java.lang.String name)Returns the length in bytes of a file in the directory.
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
return file.getLength();
|
public final long | fileModified(java.lang.String name)Returns the time the named file was last modified.
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
return file.getLastModified();
|
public final synchronized java.lang.String[] | list()Returns an array of strings, one for each file in the directory.
Set fileNames = fileMap.keySet();
String[] result = new String[fileNames.size()];
int i = 0;
Iterator it = fileNames.iterator();
while (it.hasNext())
result[i++] = (String)it.next();
return result;
|
public final org.apache.lucene.store.IndexInput | openInput(java.lang.String name)Returns a stream reading an existing file.
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file == null)
throw new FileNotFoundException(name);
return new RAMInputStream(file);
|
public final synchronized void | renameFile(java.lang.String from, java.lang.String to)Renames an existing file in the directory.
RAMFile fromFile = (RAMFile)fileMap.get(from);
if (fromFile==null)
throw new FileNotFoundException(from);
RAMFile toFile = (RAMFile)fileMap.get(to);
if (toFile!=null) {
sizeInBytes -= toFile.sizeInBytes; // updates to RAMFile.sizeInBytes synchronized on directory
toFile.directory = null;
}
fileMap.remove(from);
fileMap.put(to, fromFile);
|
public final synchronized long | sizeInBytes()Return total size in bytes of all files in this
directory. This is currently quantized to
BufferedIndexOutput.BUFFER_SIZE.
return sizeInBytes;
|
public void | touchFile(java.lang.String name)Set the modified time of an existing file to now.
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
long ts2, ts1 = System.currentTimeMillis();
do {
try {
Thread.sleep(0, 1);
} catch (InterruptedException e) {}
ts2 = System.currentTimeMillis();
} while(ts1 == ts2);
file.setLastModified(ts2);
|