add getters to FSD; change listAll to directly create String[]

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@771260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-05-04 10:16:21 +00:00
parent 6bcd89a916
commit 703f1d794b
2 changed files with 20 additions and 13 deletions

View File

@ -44,6 +44,14 @@ public class FileSwitchDirectory extends Directory {
this.lockFactory = primaryDir.getLockFactory();
}
public Directory getPrimaryDir() {
return primaryDir;
}
public Directory getSecondaryDir() {
return secondaryDir;
}
public void close() throws IOException {
if (doClose) {
try {
@ -56,16 +64,12 @@ public class FileSwitchDirectory extends Directory {
}
public String[] listAll() throws IOException {
List list = new ArrayList();
String[] ramFiles = secondaryDir.listAll();
for (int x = 0; x < ramFiles.length; x++) {
list.add(ramFiles[x]);
}
String[] fsFiles = primaryDir.listAll();
for (int x = 0; x < fsFiles.length; x++) {
list.add(fsFiles[x]);
}
return (String[]) list.toArray(new String[0]);
String[] primaryFiles = primaryDir.listAll();
String[] secondaryFiles = secondaryDir.listAll();
String[] files = new String[primaryFiles.length + secondaryFiles.length];
System.arraycopy(primaryFiles, 0, files, 0, primaryFiles.length);
System.arraycopy(secondaryFiles, 0, files, primaryFiles.length, secondaryFiles.length);
return files;
}
public String[] list() throws IOException {

View File

@ -64,8 +64,11 @@ public class TestFileSwitchDirectory extends LuceneTestCase {
}
reader.close();
writer.close();
primaryDir.close();
secondaryDir.close();
files = fsd.listAll();
for(int i=0;i<files.length;i++) {
assertNotNull(files[i]);
}
fsd.close();
}
}