refactoring so that filename extensions are in one place

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@168449 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2005-05-05 22:20:49 +00:00
parent 0209ce959b
commit c97ba92ebd
3 changed files with 18 additions and 18 deletions

View File

@ -50,6 +50,16 @@ import java.util.Set;
*/ */
public abstract class IndexReader { public abstract class IndexReader {
/**
* This array contains all filename extensions used by Lucene's index files, with
* one exception, namely the extension made up from <code>.f</code> + a number.
* Also note that two of Lucene's files (<code>deletable</code> and
* <code>segments</code>) don't have any filename extension.
*/
public final static String FILENAME_EXTENSIONS[] = new String[] {
"cfs", "fnm", "fdx", "fdt", "tii", "tis", "frq", "prx", "del",
"tvx", "tvd", "tvf", "tvp" };
public static final class FieldOption { public static final class FieldOption {
private String option; private String option;
private FieldOption() { } private FieldOption() { }

View File

@ -247,12 +247,9 @@ class SegmentReader extends IndexReader {
Vector files() throws IOException { Vector files() throws IOException {
Vector files = new Vector(16); Vector files = new Vector(16);
final String ext[] = new String[]{
"cfs", "fnm", "fdx", "fdt", "tii", "tis", "frq", "prx", "del",
"tvx", "tvd", "tvf", "tvp" };
for (int i = 0; i < ext.length; i++) { for (int i = 0; i < FILENAME_EXTENSIONS.length; i++) {
String name = segment + "." + ext[i]; String name = segment + "." + FILENAME_EXTENSIONS[i];
if (directory().fileExists(name)) if (directory().fileExists(name))
files.addElement(name); files.addElement(name);
} }

View File

@ -26,6 +26,7 @@ import java.util.Hashtable;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
/** /**
@ -47,19 +48,11 @@ public class FSDirectory extends Directory {
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String) * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/ */
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
if (name.endsWith(".cfs")) return true; for (int i = 0; i < IndexReader.FILENAME_EXTENSIONS.length; i++) {
else if (name.endsWith(".fnm")) return true; if (name.endsWith("."+IndexReader.FILENAME_EXTENSIONS[i]))
else if (name.endsWith(".fdt")) return true; return true;
else if (name.endsWith(".fdx")) return true; }
else if (name.endsWith(".frq")) return true; if (name.equals("deletable")) return true;
else if (name.endsWith(".prx")) return true;
else if (name.endsWith(".tii")) return true;
else if (name.endsWith(".tis")) return true;
else if (name.endsWith(".tvd")) return true;
else if (name.endsWith(".tvf")) return true;
else if (name.endsWith(".tvx")) return true;
else if (name.endsWith(".del")) return true;
else if (name.equals("deletable")) return true;
else if (name.equals("segments")) return true; else if (name.equals("segments")) return true;
else if (name.matches(".+\\.f\\d+")) return true; else if (name.matches(".+\\.f\\d+")) return true;
return false; return false;