Author: nextgens
Date: 2008-08-30 09:26:18 +0000 (Sat, 30 Aug 2008)
New Revision: 22243

Modified:
   trunk/freenet/src/freenet/support/io/TempBucketFactory.java
Log:
TempBucket: deal with the case where the bucket is long lived but no output 
streams have been open when it gets migrated

Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-30 
09:25:57 UTC (rev 22242)
+++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-30 
09:26:18 UTC (rev 22243)
@@ -137,7 +137,7 @@
                }

                public synchronized OutputStream getOutputStream() throws 
IOException {
-                       if(os != null)
+                       if(osIndex > 0)
                                throw new IOException("Only one OutputStream 
per bucket!");
                        return new TempBucketOutputStream(++osIndex);
                }
@@ -147,7 +147,8 @@

                        TempBucketOutputStream(short idx) throws IOException {
                                this.idx = idx;
-                               os = currentBucket.getOutputStream();
+                               if(os == null)
+                                       os = currentBucket.getOutputStream();
                        }

                        private void _maybeMigrateRamBucket(long futureSize) 
throws IOException {
@@ -320,8 +321,8 @@
                }

                public synchronized void free() {
+                       Closer.close(os);
                        closeInputStreams(true);
-                       Closer.close(os);
                        currentBucket.free();
                        if(isRAMBucket())
                                _hasFreed(currentSize);


Reply via email to