1 package org.apache.lucene.index;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 import java.io.FilenameFilter;
22 import java.util.HashSet;
25 * Filename filter that accept filenames and extensions only created by Lucene.
29 public class IndexFileNameFilter implements FilenameFilter {
31 private static IndexFileNameFilter singleton = new IndexFileNameFilter();
32 private HashSet<String> extensions;
33 private HashSet<String> extensionsInCFS;
35 // Prevent instantiation.
36 private IndexFileNameFilter() {
37 extensions = new HashSet<String>();
38 for (String ext : IndexFileNames.INDEX_EXTENSIONS) {
41 extensionsInCFS = new HashSet<String>();
42 for (String ext : IndexFileNames.INDEX_EXTENSIONS_IN_COMPOUND_FILE) {
43 extensionsInCFS.add(ext);
48 * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
50 public boolean accept(File dir, String name) {
51 int i = name.lastIndexOf('.');
53 String extension = name.substring(1+i);
54 if (extensions.contains(extension)) {
56 } else if (extension.startsWith("f") &&
57 extension.matches("f\\d+")) {
59 } else if (extension.startsWith("s") &&
60 extension.matches("s\\d+")) {
64 if (name.equals(IndexFileNames.DELETABLE)) return true;
65 else if (name.startsWith(IndexFileNames.SEGMENTS)) return true;
71 * Returns true if this is a file that would be contained
72 * in a CFS file. This function should only be called on
73 * files that pass the above "accept" (ie, are already
74 * known to be a Lucene index file).
76 public boolean isCFSFile(String name) {
77 int i = name.lastIndexOf('.');
79 String extension = name.substring(1+i);
80 if (extensionsInCFS.contains(extension)) {
83 if (extension.startsWith("f") &&
84 extension.matches("f\\d+")) {
91 public static IndexFileNameFilter getFilter() {