Constructors Summary |
---|
public RAMDirectory()Constructs an empty {@link Directory}.
|
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.
this(dir, false);
|
private RAMDirectory(Directory dir, boolean closeDir)
final String[] files = dir.list();
for (int i = 0; i < files.length; i++) {
// make place on ram disk
OutputStream os = createFile(files[i]);
// read current file
InputStream is = dir.openFile(files[i]);
// and copy to ram disk
int len = (int) is.length();
byte[] buf = new byte[len];
is.readBytes(buf, 0, len);
os.writeBytes(buf, len);
// graceful cleanup
is.close();
os.close();
}
if(closeDir)
dir.close();
|
public RAMDirectory(File dir)Creates a new RAMDirectory instance from the {@link FSDirectory}.
this(FSDirectory.getDirectory(dir, false), true);
|
public RAMDirectory(String dir)Creates a new RAMDirectory instance from the {@link FSDirectory}.
this(FSDirectory.getDirectory(dir, false), true);
|
Methods Summary |
---|
public final void | close()Closes the store to future operations.
|
public final org.apache.lucene.store.OutputStream | createFile(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();
files.put(name, file);
return new RAMOutputStream(file);
|
public final void | deleteFile(java.lang.String name)Removes an existing file in the directory.
files.remove(name);
|
public final boolean | fileExists(java.lang.String name)Returns true iff the named file exists in this directory.
RAMFile file = (RAMFile)files.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 = (RAMFile)files.get(name);
return file.length;
|
public final long | fileModified(java.lang.String name)Returns the time the named file was last modified.
RAMFile file = (RAMFile)files.get(name);
return file.lastModified;
|
public final java.lang.String[] | list()Returns an array of strings, one for each file in the directory.
String[] result = new String[files.size()];
int i = 0;
Enumeration names = files.keys();
while (names.hasMoreElements())
result[i++] = (String)names.nextElement();
return result;
|
public final org.apache.lucene.store.Lock | makeLock(java.lang.String name)Construct a {@link Lock}.
return new Lock() {
public boolean obtain() throws IOException {
synchronized (files) {
if (!fileExists(name)) {
createFile(name).close();
return true;
}
return false;
}
}
public void release() {
deleteFile(name);
}
public boolean isLocked() {
return fileExists(name);
}
};
|
public final org.apache.lucene.store.InputStream | openFile(java.lang.String name)Returns a stream reading an existing file.
RAMFile file = (RAMFile)files.get(name);
return new RAMInputStream(file);
|
public final void | renameFile(java.lang.String from, java.lang.String to)Removes an existing file in the directory.
RAMFile file = (RAMFile)files.get(from);
files.remove(from);
files.put(to, file);
|
public void | touchFile(java.lang.String name)Set the modified time of an existing file to now.
// final boolean MONITOR = false;
RAMFile file = (RAMFile)files.get(name);
long ts2, ts1 = System.currentTimeMillis();
do {
try {
Thread.sleep(0, 1);
} catch (InterruptedException e) {}
ts2 = System.currentTimeMillis();
// if (MONITOR) {
// count++;
// }
} while(ts1 == ts2);
file.lastModified = ts2;
// if (MONITOR)
// System.out.println("SLEEP COUNT: " + count);
|