| 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 = 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 = fileMap.get(name);
if (file!=null) {
fileMap.remove(name);
file.directory = null;
sizeInBytes -= file.sizeInBytes;
} else
throw new FileNotFoundException(name);
}
Removes an existing file in the directory. |
public final boolean fileExists(String name) {
ensureOpen();
RAMFile file;
synchronized (this) {
file = 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 = 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 = 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[] listAll() {
ensureOpen();
Set< String > fileNames = fileMap.keySet();
String[] result = new String[fileNames.size()];
int i = 0;
for(final String fileName: fileNames)
result[i++] = fileName;
return result;
}
|
public IndexInput openInput(String name) throws IOException {
ensureOpen();
RAMFile file;
synchronized (this) {
file = fileMap.get(name);
}
if (file == null)
throw new FileNotFoundException(name);
return new RAMInputStream(file);
}
Returns a stream reading an existing file. |
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 = fileMap.get(name);
}
if (file==null)
throw new FileNotFoundException(name);
long ts2, ts1 = System.currentTimeMillis();
do {
try {
Thread.sleep(0, 1);
} catch (InterruptedException ie) {
throw new ThreadInterruptedException(ie);
}
ts2 = System.currentTimeMillis();
} while(ts1 == ts2);
file.setLastModified(ts2);
}
Set the modified time of an existing file to now. |