Author: nextgens
Date: 2008-08-13 14:21:57 +0000 (Wed, 13 Aug 2008)
New Revision: 21807

Modified:
   trunk/freenet/src/freenet/support/io/ArrayBucket.java
   trunk/freenet/src/freenet/support/io/TempBucketFactory.java
Log:
Throw if we attempt to write to a read-only ArrayBucket

Modified: trunk/freenet/src/freenet/support/io/ArrayBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/ArrayBucket.java       2008-08-13 
14:15:25 UTC (rev 21806)
+++ trunk/freenet/src/freenet/support/io/ArrayBucket.java       2008-08-13 
14:21:57 UTC (rev 21807)
@@ -46,6 +46,7 @@
                return new ArrayBucketInputStream();
        }

+       @Override
        public String toString() {
                StringBuffer s = new StringBuffer(250);
                for (Iterator i = data.iterator(); i.hasNext();) {
@@ -83,11 +84,23 @@
                public ArrayBucketOutputStream() {
                        super();
                }
+               
+               @Override
+               public synchronized void write(byte b[], int off, int len) {
+                       if(readOnly) throw new IllegalStateException("Read 
only");
+                       super.write(b, off, len);
+               }
+               
+               @Override
+               public synchronized void write(int b) {
+                       if(readOnly) throw new IllegalStateException("Read 
only");
+                       super.write(b);
+               }

+               @Override
                public void close() throws IOException {
                        data.add(super.toByteArray());
                        if(readOnly) throw new IOException("Read only");
-                       // FIXME maybe we should throw on write instead? :)
                }
        }

@@ -121,10 +134,12 @@
                        }
                }

+               @Override
                public int read(byte[] b) {
                        return priv_read(b, 0, b.length);
                }

+               @Override
                public int read(byte[] b, int off, int len) {
                        return priv_read(b, off, len);
                }
@@ -146,6 +161,7 @@
                        }
                }

+               @Override
                public int available() {
                        if (in == null) {
                                if (i.hasNext()) {

Modified: trunk/freenet/src/freenet/support/io/TempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-13 
14:15:25 UTC (rev 21806)
+++ trunk/freenet/src/freenet/support/io/TempBucketFactory.java 2008-08-13 
14:21:57 UTC (rev 21807)
@@ -36,7 +36,6 @@
        }

        private final FilenameGenerator filenameGenerator;
-       private final ArrayBucketFactory arrayBucketFactory;
        private long bytesInUse = 0;

        public final static long defaultIncrement = 4096;
@@ -53,7 +52,6 @@
        // Storage accounting disabled by default.
        public TempBucketFactory(FilenameGenerator filenameGenerator, long 
maxBucketSizeKeptInRam, long maxRamUsed, RandomSource strongPRNG, Random 
weakPRNG, boolean reallyEncrypt) {
                this.filenameGenerator = filenameGenerator;
-               this.arrayBucketFactory = new ArrayBucketFactory();
                this.maxRamUsed = maxRamUsed;
                this.maxRAMBucketSize = maxBucketSizeKeptInRam;
                this.strongPRNG = strongPRNG;


Reply via email to