| Method from org.apache.lucene.store.RAMDirectory Detail: |
public void close() {
isOpen = false;
fileMap = null;
}
Closes the store to future operations, releasing associated memory. |
public IndexOutput createOutput(String name) throws IOException {
ensureOpen();
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);
}
Creates a new, empty file in the directory with the given name. Returns a stream writing this file. |
public synchronized void deleteFile(String name) throws IOException {
ensureOpen();
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);
}
Removes an existing file in the directory. |
public final boolean fileExists(String name) {
ensureOpen();
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
return file != null;
}
Returns true iff the named file exists in this directory. |
public final long fileLength(String name) throws IOException {
ensureOpen();
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
return file.getLength();
}
Returns the length in bytes of a file in the directory. |
public final long fileModified(String name) throws IOException {
ensureOpen();
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
return file.getLastModified();
}
Returns the time the named file was last modified. |
public final synchronized String[] list() {
ensureOpen();
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;
}
Returns an array of strings, one for each file in the directory. |
public IndexInput openInput(String name) throws IOException {
ensureOpen();
RAMFile file;
synchronized (this) {
file = (RAMFile)fileMap.get(name);
}
if (file == null)
throw new FileNotFoundException(name);
return new RAMInputStream(file);
}
Returns a stream reading an existing file. |
public final synchronized void renameFile(String from,
String to) throws IOException {
ensureOpen();
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);
} Deprecated!
Renames an existing file in the directory. |
public final synchronized long sizeInBytes() {
ensureOpen();
return sizeInBytes;
}
Return total size in bytes of all files in this
directory. This is currently quantized to
RAMOutputStream.BUFFER_SIZE. |
public void touchFile(String name) throws IOException {
ensureOpen();
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);
}
Set the modified time of an existing file to now. |