Apache Lucene open-source search software
Added convenience RAMDirectory constructors taking File and String arguments, for easy FSDirectory to RAMDirectory conversion.
Otis Gospodnetic5b910b44b303
diff --git a/CHANGES.txt b/CHANGES.txtindex 19ef764734d..481ef06716b 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -95,13 +95,14 @@ $Id$18. Added a public, extensible scoring API. For details, see thejavadoc for org.apache.lucene.search.Similarity.-+19. Fixed return of Hits.id() from float to int. (Terry Steichen via Peter).20. Added getFieldNames() to IndexReader and Segment(s)Reader classes.(Peter Mularien via otis)21. Added getFields(String) and getValues(String) methods.+ Contributed by Rasik Pandey on 2002-10-09(Rasik Pandey via otis)22. Revised internal search APIs. Changes include:@@ -142,9 +143,12 @@ $Id$Caution: These are extensive changes and they have not yet beentested extensively. Bug reports are appreciated.+ (cutting)++ 23. Added convenience RAMDirectory constructors taking File and String+ arguments, for easy FSDirectory to RAMDirectory conversion.- Contributed by Rasik Pandey on 2002-10-091.2 RC61. Changed QueryParser.jj to have "?" be a special character whichdiff --git a/src/java/org/apache/lucene/store/RAMDirectory.java b/src/java/org/apache/lucene/store/RAMDirectory.javaindex 57c9e4de284..12b5a58ad73 100644--- a/src/java/org/apache/lucene/store/RAMDirectory.java+++ b/src/java/org/apache/lucene/store/RAMDirectory.java@@ -55,6 +55,7 @@ package org.apache.lucene.store;*/import java.io.IOException;+import java.io.File;import java.util.Vector;import java.util.Hashtable;import java.util.Enumeration;@@ -63,7 +64,11 @@ import org.apache.lucene.store.Directory;import org.apache.lucene.store.InputStream;import org.apache.lucene.store.OutputStream;-/** A memory-resident {@link Directory} implementation. */+/**+ * A memory-resident {@link Directory} implementation.+ *+ * @version $Id$+ */public final class RAMDirectory extends Directory {Hashtable files = new Hashtable();@@ -78,16 +83,16 @@ public final class RAMDirectory extends Directory {* <P>* This should be used only with indices that can fit into memory.*- * @param d a <code>Directory</code> value+ * @param dir a <code>Directory</code> value* @exception IOException if an error occurs*/- public RAMDirectory(Directory d) throws IOException {- final String[] ar = d.list();+ public RAMDirectory(Directory dir) throws IOException {+ final String[] ar = dir.list();for (int i = 0; i < ar.length; i++) {// make place on ram diskOutputStream os = createFile(ar[i]);// read current file- InputStream is = d.openFile(ar[i]);+ InputStream is = dir.openFile(ar[i]);// and copy to ram diskint len = (int) is.length();byte[] buf = new byte[len];@@ -99,6 +104,24 @@ public final class RAMDirectory extends Directory {}}+ /**+ * Creates a new <code>RAMDirectory</code> instance from the {@link FSDirectory}.+ *+ * @param dir a <code>File</code> specifying the index directory+ */+ public RAMDirectory(File dir) throws IOException {+ this(FSDirectory.getDirectory(dir, false));+ }++ /**+ * Creates a new <code>RAMDirectory</code> instance from the {@link FSDirectory}.+ *+ * @param dir a <code>String</code> specifying the full index directory path+ */+ public RAMDirectory(String dir) throws IOException {+ this(FSDirectory.getDirectory(dir, false));+ }+/** Returns an array of strings, one for each file in the directory. */public final String[] list() {String[] result = new String[files.size()];