Added convenience RAMDirectory constructors taking File and String

arguments, for easy FSDirectory to RAMDirectory conversion.


git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@149925 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Otis Gospodnetic 2003-01-14 03:41:05 +00:00
parent a7486068de
commit 5b910b44b3
2 changed files with 34 additions and 7 deletions

View File

@ -95,13 +95,14 @@ $Id$
18. Added a public, extensible scoring API. For details, see the
javadoc 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 been
tested 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-09
1.2 RC6
1. Changed QueryParser.jj to have "?" be a special character which

View File

@ -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 disk
OutputStream os = createFile(ar[i]);
// read current file
InputStream is = d.openFile(ar[i]);
InputStream is = dir.openFile(ar[i]);
// and copy to ram disk
int 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()];