clean unused code

This commit is contained in:
kimchy 2011-06-28 11:37:52 +03:00
parent 73898067b8
commit 2e83a2f045
2 changed files with 3 additions and 109 deletions

View File

@ -19,20 +19,11 @@
package org.elasticsearch.common.lucene; package org.elasticsearch.common.lucene;
import org.apache.lucene.index.IndexCommit;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.elasticsearch.common.io.Closeables;
import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.index.store.support.ForceSyncDirectory;
import java.io.*; import java.io.FileNotFoundException;
import java.util.Collection; import java.io.IOException;
import static org.elasticsearch.common.io.FileSystemUtils.*;
/** /**
* A set of utilities for Lucene {@link Directory}. * A set of utilities for Lucene {@link Directory}.
@ -57,103 +48,6 @@ public class Directories {
return new ByteSizeValue(estimatedSize); return new ByteSizeValue(estimatedSize);
} }
/**
* Lists all the commit point in a directory.
*/
public static Collection<IndexCommit> listCommits(Directory directory) throws IOException {
return IndexReader.listCommits(directory);
}
public static void copyFromDirectory(Directory dir, String fileName, File copyTo, boolean nativeCopy) throws IOException {
if (nativeCopy && (dir instanceof FSDirectory)) {
if (!copyTo.exists()) {
copyTo.createNewFile();
}
copyFile(new File(((FSDirectory) dir).getDirectory(), fileName), copyTo);
} else {
copyFromDirectory(dir.openInput(fileName), new FileOutputStream(copyTo));
}
// sync the file
syncFile(copyTo);
}
public static void copyFromDirectory(Directory dir, String fileName, OutputStream os) throws IOException {
copyFromDirectory(dir.openInput(fileName), os);
}
public static void copyFromDirectory(IndexInput ii, OutputStream os) throws IOException {
final int BUFFER_SIZE = ii.length() < 16384 ? (int) ii.length() : 16384;
byte[] buffer = new byte[BUFFER_SIZE];
try {
long len = ii.length();
long readCount = 0;
while (readCount < len) {
int toRead = readCount + BUFFER_SIZE > len ? (int) (len - readCount) : BUFFER_SIZE;
ii.readBytes(buffer, 0, toRead, false);
readCount += toRead;
os.write(buffer, 0, toRead);
}
} finally {
Closeables.closeQuietly(os);
Closeables.closeQuietly(ii);
}
}
public static void copyToDirectory(File copyFrom, Directory dir, String fileName, boolean nativeCopy) throws IOException {
if (nativeCopy && (dir instanceof FSDirectory)) {
File destinationFile = new File(((FSDirectory) dir).getDirectory(), fileName);
if (!destinationFile.exists()) {
destinationFile.createNewFile();
}
copyFile(copyFrom, destinationFile);
} else {
FileInputStream is = null;
IndexOutput output = null;
try {
is = new FileInputStream(copyFrom);
output = dir.createOutput(fileName);
copyToDirectory(is, output);
} finally {
Closeables.closeQuietly(is);
Closeables.closeQuietly(output);
}
}
sync(dir, fileName);
}
public static void copyToDirectory(InputStream is, Directory dir, String fileName) throws IOException {
IndexOutput output = null;
try {
output = dir.createOutput(fileName);
copyToDirectory(is, output);
} finally {
Closeables.closeQuietly(is);
Closeables.closeQuietly(output);
}
sync(dir, fileName);
}
public static void sync(Directory dir, String fileName) throws IOException {
if (dir instanceof ForceSyncDirectory) {
((ForceSyncDirectory) dir).forceSync(fileName);
} else {
dir.sync(fileName);
}
}
public static void copyToDirectory(InputStream is, IndexOutput io) throws IOException {
byte[] buffer = new byte[16384];
int len;
try {
while ((len = is.read(buffer)) != -1) {
io.writeBytes(buffer, len);
}
} finally {
Closeables.closeQuietly(io);
Closeables.closeQuietly(is);
}
}
private Directories() { private Directories() {
} }

View File

@ -28,7 +28,7 @@ import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import static org.elasticsearch.common.lucene.Directories.*; import static org.apache.lucene.index.IndexReader.*;
import static org.elasticsearch.common.lucene.DocumentBuilder.*; import static org.elasticsearch.common.lucene.DocumentBuilder.*;
import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*; import static org.elasticsearch.common.settings.ImmutableSettings.Builder.*;
import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.MatcherAssert.*;