mirror of https://github.com/apache/lucene.git
LUCENE-869: Changed FSIndexInput and FSIndexOutput to inner classes of FSDirectory to enable extensibility of these classes.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@532259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a181157bfd
commit
d7ea0e5b19
|
@ -46,6 +46,9 @@ API Changes
|
|||
combination when caching is desired.
|
||||
(Chris Hostetter, Otis Gospodnetic)
|
||||
|
||||
8. LUCENE-869: Changed FSIndexInput and FSIndexOutput to inner classes of FSDirectory
|
||||
to enable extensibility of these classes.
|
||||
|
||||
Bug fixes
|
||||
|
||||
1. LUCENE-804: Fixed build.xml to pack a fully compilable src dist. (Doron Cohen)
|
||||
|
|
|
@ -487,126 +487,124 @@ public class FSDirectory extends Directory {
|
|||
public String toString() {
|
||||
return this.getClass().getName() + "@" + directory;
|
||||
}
|
||||
}
|
||||
|
||||
protected static class FSIndexInput extends BufferedIndexInput {
|
||||
|
||||
private static class Descriptor extends RandomAccessFile {
|
||||
// remember if the file is open, so that we don't try to close it
|
||||
// more than once
|
||||
private boolean isOpen;
|
||||
long position;
|
||||
final long length;
|
||||
|
||||
public Descriptor(File file, String mode) throws IOException {
|
||||
super(file, mode);
|
||||
isOpen=true;
|
||||
length=length();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (isOpen) {
|
||||
isOpen=false;
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
close();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final Descriptor file;
|
||||
boolean isClone;
|
||||
|
||||
public FSIndexInput(File path) throws IOException {
|
||||
file = new Descriptor(path, "r");
|
||||
}
|
||||
|
||||
/** IndexInput methods */
|
||||
protected void readInternal(byte[] b, int offset, int len)
|
||||
throws IOException {
|
||||
synchronized (file) {
|
||||
long position = getFilePointer();
|
||||
if (position != file.position) {
|
||||
file.seek(position);
|
||||
file.position = position;
|
||||
}
|
||||
int total = 0;
|
||||
do {
|
||||
int i = file.read(b, offset+total, len-total);
|
||||
if (i == -1)
|
||||
throw new IOException("read past EOF");
|
||||
file.position += i;
|
||||
total += i;
|
||||
} while (total < len);
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// only close the file if this is not a clone
|
||||
if (!isClone) file.close();
|
||||
}
|
||||
|
||||
protected void seekInternal(long position) {
|
||||
}
|
||||
|
||||
public long length() {
|
||||
return file.length;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
FSIndexInput clone = (FSIndexInput)super.clone();
|
||||
clone.isClone = true;
|
||||
return clone;
|
||||
}
|
||||
|
||||
/** Method used for testing. Returns true if the underlying
|
||||
* file descriptor is valid.
|
||||
*/
|
||||
boolean isFDValid() throws IOException {
|
||||
return file.getFD().valid();
|
||||
}
|
||||
}
|
||||
|
||||
class FSIndexInput extends BufferedIndexInput {
|
||||
|
||||
private static class Descriptor extends RandomAccessFile {
|
||||
protected static class FSIndexOutput extends BufferedIndexOutput {
|
||||
RandomAccessFile file = null;
|
||||
|
||||
// remember if the file is open, so that we don't try to close it
|
||||
// more than once
|
||||
private boolean isOpen;
|
||||
long position;
|
||||
final long length;
|
||||
|
||||
public Descriptor(File file, String mode) throws IOException {
|
||||
super(file, mode);
|
||||
isOpen=true;
|
||||
length=length();
|
||||
|
||||
public FSIndexOutput(File path) throws IOException {
|
||||
file = new RandomAccessFile(path, "rw");
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
/** output methods: */
|
||||
public void flushBuffer(byte[] b, int offset, int size) throws IOException {
|
||||
file.write(b, offset, size);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// only close the file if it has not been closed yet
|
||||
if (isOpen) {
|
||||
isOpen=false;
|
||||
super.close();
|
||||
file.close();
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
close();
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
/** Random-access methods */
|
||||
public void seek(long pos) throws IOException {
|
||||
super.seek(pos);
|
||||
file.seek(pos);
|
||||
}
|
||||
}
|
||||
|
||||
private final Descriptor file;
|
||||
boolean isClone;
|
||||
|
||||
public FSIndexInput(File path) throws IOException {
|
||||
file = new Descriptor(path, "r");
|
||||
}
|
||||
|
||||
/** IndexInput methods */
|
||||
protected void readInternal(byte[] b, int offset, int len)
|
||||
throws IOException {
|
||||
synchronized (file) {
|
||||
long position = getFilePointer();
|
||||
if (position != file.position) {
|
||||
file.seek(position);
|
||||
file.position = position;
|
||||
}
|
||||
int total = 0;
|
||||
do {
|
||||
int i = file.read(b, offset+total, len-total);
|
||||
if (i == -1)
|
||||
throw new IOException("read past EOF");
|
||||
file.position += i;
|
||||
total += i;
|
||||
} while (total < len);
|
||||
public long length() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// only close the file if this is not a clone
|
||||
if (!isClone) file.close();
|
||||
}
|
||||
|
||||
protected void seekInternal(long position) {
|
||||
}
|
||||
|
||||
public long length() {
|
||||
return file.length;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
FSIndexInput clone = (FSIndexInput)super.clone();
|
||||
clone.isClone = true;
|
||||
return clone;
|
||||
}
|
||||
|
||||
/** Method used for testing. Returns true if the underlying
|
||||
* file descriptor is valid.
|
||||
*/
|
||||
boolean isFDValid() throws IOException {
|
||||
return file.getFD().valid();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class FSIndexOutput extends BufferedIndexOutput {
|
||||
RandomAccessFile file = null;
|
||||
|
||||
// remember if the file is open, so that we don't try to close it
|
||||
// more than once
|
||||
private boolean isOpen;
|
||||
|
||||
public FSIndexOutput(File path) throws IOException {
|
||||
file = new RandomAccessFile(path, "rw");
|
||||
isOpen = true;
|
||||
}
|
||||
|
||||
/** output methods: */
|
||||
public void flushBuffer(byte[] b, int offset, int size) throws IOException {
|
||||
file.write(b, offset, size);
|
||||
}
|
||||
public void close() throws IOException {
|
||||
// only close the file if it has not been closed yet
|
||||
if (isOpen) {
|
||||
super.close();
|
||||
file.close();
|
||||
isOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Random-access methods */
|
||||
public void seek(long pos) throws IOException {
|
||||
super.seek(pos);
|
||||
file.seek(pos);
|
||||
}
|
||||
public long length() throws IOException {
|
||||
return file.length();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.apache.lucene.store;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.lucene.store.FSDirectory.FSIndexInput;
|
||||
|
||||
/** This class provides access to package-level features defined in the
|
||||
* store package. It is used for testing only.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue