Author: nextgens
Date: 2008-08-25 16:07:42 +0000 (Mon, 25 Aug 2008)
New Revision: 22136

Modified:
   trunk/freenet/src/freenet/support/io/TempBucketFactory.java
Log:
TempBucketFactory: maybe fix an issue with InputStreams

Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-25 
13:53:29 UTC (rev 22135)
+++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-25 
16:07:42 UTC (rev 22136)
@@ -148,7 +148,7 @@
                        }

                        @Override
-                       public void write(int b) throws IOException {
+                       public final void write(int b) throws IOException {
                                synchronized(currentBucket) {
                                        long futurSize = currentSize + 1;
                                        _maybeMigrateRamBucket(futurSize);
@@ -161,7 +161,7 @@
                        }

                        @Override
-                       public void write(byte b[], int off, int len) throws 
IOException {
+                       public final void write(byte b[], int off, int len) 
throws IOException {
                                synchronized(currentBucket) {
                                        long futurSize = currentSize + len;
                                        _maybeMigrateRamBucket(futurSize);
@@ -174,7 +174,7 @@
                        }

                        @Override
-                       public void flush() throws IOException {
+                       public final void flush() throws IOException {
                                synchronized(currentBucket) {
                                        _maybeMigrateRamBucket(currentSize);
                                        _maybeResetOutputStream();
@@ -183,7 +183,7 @@
                        }

                        @Override
-                       public void close() throws IOException {
+                       public final void close() throws IOException {
                                synchronized(currentBucket) {
                                        _maybeMigrateRamBucket(currentSize);
                                        _maybeResetOutputStream();
@@ -199,25 +199,30 @@

                private class TempBucketInputStream extends InputStream {
                        private InputStream is;
+                       private long index = 0;

                        private void _maybeResetInputStream() throws 
IOException {
                                if(shouldResetIS) {
                                        Closer.close(is);
                                        is = currentBucket.getInputStream();
+                                       is.skip(index);
                                        shouldResetIS = false;
                                }
                        }

                        @Override
-                       public int read() throws IOException {
+                       public final int read() throws IOException {
                                synchronized(currentBucket) {
                                        _maybeResetInputStream();
-                                       return is.read();
+                                       int toReturn = is.read();
+                                       if(toReturn > -1)
+                                               index++;
+                                       return toReturn;
                                }
                        }

                        @Override
-                       public void close() throws IOException {
+                       public final void close() throws IOException {
                                synchronized(currentBucket) {
                                        _maybeResetInputStream();
                                        Closer.close(is);


Reply via email to