Author: nextgens
Date: 2008-08-30 21:20:53 +0000 (Sat, 30 Aug 2008)
New Revision: 22259
Modified:
trunk/freenet/src/freenet/support/io/TempBucketFactory.java
Log:
TempBucket: back the InputStream with a BufferedInputStream so that we can use
markSupported()
Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-30
20:34:55 UTC (rev 22258)
+++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-30
21:20:53 UTC (rev 22259)
@@ -13,6 +13,7 @@
import freenet.support.api.Bucket;
import freenet.support.api.BucketFactory;
+import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
@@ -228,7 +229,7 @@
private class TempBucketInputStream extends InputStream {
/** The current InputStream we use from the underlying
bucket */
- private InputStream currentIS;
+ private BufferedInputStream currentIS;
/** Keep a link to the current OutputStream to know
when to reset the stream */
private OutputStream currentOS;
/** Keep a counter to know where we are on the stream
(useful when we have to reset and skip) */
@@ -238,7 +239,10 @@
TempBucketInputStream(short idx) throws IOException {
this.idx = idx;
- this.currentIS = currentBucket.getInputStream();
+ // Neither bucket types
(ArrayBuckets|TempFileBuckets) do support marks...
+ // So we use a BufferedInputStream which does.
+ // TODO: Obviously we should implement it.
+ this.currentIS = new
BufferedInputStream(currentBucket.getInputStream());
this.currentOS = os;
}
@@ -248,7 +252,7 @@
if(currentOS != os) {
Closer.close(currentIS);
- currentIS =
currentBucket.getInputStream();
+ currentIS = new
BufferedInputStream(currentBucket.getInputStream());
currentIS.skip(index);
currentOS = os;
}
@@ -299,10 +303,26 @@
@Override
public boolean markSupported() {
- return false;
+ synchronized(TempBucket.this) {
+ return currentIS.markSupported();
+ }
}
@Override
+ public void mark(int readlimit) {
+ synchronized(TempBucket.this) {
+ currentIS.mark(readlimit);
+ }
+ }
+
+ @Override
+ public void reset() throws IOException {
+ synchronized(TempBucket.this) {
+ currentIS.reset();
+ }
+ }
+
+ @Override
public final void close() throws IOException {
synchronized(TempBucket.this) {
Closer.close(currentIS);