Apache Lucene open-source search software
LUCENE-869: Changed FSIndexInput and FSIndexOutput to inner classes of FSDirectory to enable extensibility of these classes.
Michael Buschd7ea0e5b1907
diff --git a/CHANGES.txt b/CHANGES.txtindex cf7c49a03f5..6c28b4e7df6 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -46,6 +46,9 @@ API Changescombination 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 fixes1. LUCENE-804: Fixed build.xml to pack a fully compilable src dist. (Doron Cohen)diff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.javaindex 3fb3a59d0bb..4196766eaa1 100644--- a/src/java/org/apache/lucene/store/FSDirectory.java+++ b/src/java/org/apache/lucene/store/FSDirectory.java@@ -487,126 +487,124 @@ public class FSDirectory extends Directory {public String toString() {return this.getClass().getName() + "@" + directory;}-}--class FSIndexInput extends BufferedIndexInput {+ 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();+ }+ }- 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 onceprivate 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 yetif (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();- }-}diff --git a/src/test/org/apache/lucene/store/_TestHelper.java b/src/test/org/apache/lucene/store/_TestHelper.javaindex b3783fb6dd4..efcadf84e55 100644--- a/src/test/org/apache/lucene/store/_TestHelper.java+++ b/src/test/org/apache/lucene/store/_TestHelper.java@@ -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.*/