Index: src/java/org/apache/lucene/store/RAMDirectory.java
===================================================================
--- src/java/org/apache/lucene/store/RAMDirectory.java	(revision 476181)
+++ src/java/org/apache/lucene/store/RAMDirectory.java	(working copy)
@@ -39,6 +39,7 @@
   private static final long serialVersionUID = 1l;
 
   Hashtable files = new Hashtable();
+  long sizeInBytes;  // synchronized on this (use AtomicLong in Java5)
 
   /** Constructs an empty {@link Directory}. */
   public RAMDirectory() {
@@ -70,6 +71,7 @@
       IndexInput is = dir.openInput(files[i]);
       // and copy to ram disk
       long len = is.length();
+      sizeInBytes += len;  // maintain total directory size
       long readCount = 0;
       while (readCount < len) {
         int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? (int)(len - readCount) : BufferedIndexOutput.BUFFER_SIZE;
@@ -156,24 +158,40 @@
 
   /** Removes an existing file in the directory. */
   public final void deleteFile(String name) {
-    files.remove(name);
+    RAMFile file = (RAMFile)files.remove(name);
+    if (file!=null) {
+      synchronized(this) {sizeInBytes -= file.length;}
+    }
   }
 
-  /** Removes an existing file in the directory. */
+  /** Renames an existing file in the directory. */
   public final void renameFile(String from, String to) {
-    RAMFile file = (RAMFile)files.get(from);
-    files.remove(from);
-    files.put(to, file);
+    synchronized (files) {
+      RAMFile file = (RAMFile)files.remove(from);
+      if (file!=null) files.put(to, file);
+    }
   }
 
   /** Creates a new, empty file in the directory with the given name.
       Returns a stream writing this file. */
   public final IndexOutput createOutput(String name) {
-    RAMFile file = new RAMFile();
+    final RAMFile file = new RAMFile();
     files.put(name, file);
-    return new RAMOutputStream(file);
+    return new RAMOutputStream(file) {
+      public void close() throws IOException {
+        synchronized(RAMDirectory.this) {sizeInBytes += file.length;}
+        super.close();
+      }
+    };
   }
 
+  /** Returns the size in bytes of all closed files.
+   * Files that are currently being written to are not included.
+   */
+  public long getSizeInBytes() {
+    synchronized(this) { return sizeInBytes; }
+  }
+
   /** Returns a stream reading an existing file. */
   public final IndexInput openInput(String name) {
     RAMFile file = (RAMFile)files.get(name);
