goller 2003/11/20 11:01:44
Modified: src/java/org/apache/lucene/index CompoundFileReader.java
Log:
avoid double buffering in CSInputStream
Revision Changes Path
1.3 +13 -36
jakarta-lucene/src/java/org/apache/lucene/index/CompoundFileReader.java
Index: CompoundFileReader.java
===================================================================
RCS file:
/home/cvs/jakarta-lucene/src/java/org/apache/lucene/index/CompoundFileReader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CompoundFileReader.java 13 Oct 2003 14:18:04 -0000 1.2
+++ CompoundFileReader.java 20 Nov 2003 19:01:44 -0000 1.3
@@ -235,15 +235,12 @@
InputStream base;
long fileOffset;
- CSInputStream(final InputStream base,
- final long fileOffset,
- final long length)
- throws IOException
+ CSInputStream(final InputStream base, final long fileOffset, final long
length)
+ throws IOException
{
- this.base = (InputStream) base.clone();
+ this.base = base;
this.fileOffset = fileOffset;
this.length = length; // variable in the superclass
- seekInternal(0); // position to the adjusted 0th byte
}
/** Expert: implements buffer refill. Reads bytes from the current
@@ -255,43 +252,23 @@
protected void readInternal(byte[] b, int offset, int len)
throws IOException
{
- base.readBytes(b, offset, len);
+ synchronized (base) {
+ long start = getFilePointer();
+ if(start + len > length)
+ throw new IOException("read past EOF");
+ base.seek(fileOffset + start);
+ base.readBytes(b, offset, len);
+ }
}
/** Expert: implements seek. Sets current position in this file, where
* the next [EMAIL PROTECTED] #readInternal(byte[],int,int)} will occur.
* @see #readInternal(byte[],int,int)
*/
- protected void seekInternal(long pos) throws IOException
- {
- if (pos > 0 && pos >= length)
- throw new IOException("Seek past the end of file");
-
- if (pos < 0)
- throw new IOException("Seek to a negative offset");
-
- base.seek(fileOffset + pos);
- }
+ protected void seekInternal(long pos) throws IOException {}
/** Closes the stream to futher operations. */
- public void close() throws IOException
- {
- base.close();
- }
+ public void close() throws IOException {}
- /** Returns a clone of this stream.
- *
- * <p>Clones of a stream access the same data, and are positioned at the
same
- * point as the stream they were cloned from.
- *
- * <p>Expert: Subclasses must ensure that clones may be positioned at
- * different points in the input from each other and from the stream they
- * were cloned from.
- */
- public Object clone() {
- CSInputStream other = (CSInputStream) super.clone();
- other.base = (InputStream) base.clone();
- return other;
- }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]