You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@lucene.apache.org by bu...@apache.org on 2007/04/25 10:46:15 UTC
svn commit: r532259 - in /lucene/java/trunk: CHANGES.txt
src/java/org/apache/lucene/store/FSDirectory.java
src/test/org/apache/lucene/store/_TestHelper.java
Author: buschmi
Date: Wed Apr 25 01:46:14 2007
New Revision: 532259
URL: http://svn.apache.org/viewvc?view=rev&rev=532259
Log:
LUCENE-869: Changed FSIndexInput and FSIndexOutput to inner classes of FSDirectory to enable extensibility of these classes.
Modified:
lucene/java/trunk/CHANGES.txt
lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
lucene/java/trunk/src/test/org/apache/lucene/store/_TestHelper.java
Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=532259&r1=532258&r2=532259
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed Apr 25 01:46:14 2007
@@ -46,6 +46,9 @@
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)
Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=532259&r1=532258&r2=532259
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Wed Apr 25 01:46:14 2007
@@ -487,126 +487,124 @@
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();
- }
- }
- }
-
- 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);
+
+ /** Random-access methods */
+ public void seek(long pos) throws IOException {
+ super.seek(pos);
+ file.seek(pos);
}
- }
-
- 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;
+ public long length() throws IOException {
+ return file.length();
}
+
}
-
- /** Random-access methods */
- public void seek(long pos) throws IOException {
- super.seek(pos);
- file.seek(pos);
- }
- public long length() throws IOException {
- return file.length();
- }
-
}
Modified: lucene/java/trunk/src/test/org/apache/lucene/store/_TestHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/_TestHelper.java?view=diff&rev=532259&r1=532258&r2=532259
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/_TestHelper.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/_TestHelper.java Wed Apr 25 01:46:14 2007
@@ -2,6 +2,8 @@
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.
*/