Author: toad
Date: 2006-07-25 16:48:20 +0000 (Tue, 25 Jul 2006)
New Revision: 9753

Modified:
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/support/io/ReadOnlyFileSliceBucket.java
   trunk/freenet/src/freenet/support/io/SerializableToFieldSetBucketUtil.java
Log:
896: Fix insert resuming when inserting from a file with DontCompress=true.

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-07-25 16:18:57 UTC (rev 
9752)
+++ trunk/freenet/src/freenet/node/Version.java 2006-07-25 16:48:20 UTC (rev 
9753)
@@ -18,7 +18,7 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 895;
+       private static final int buildNumber = 896;

        /** Oldest build of Fred we will talk to */
        private static final int oldLastGoodBuild = 870;

Modified: trunk/freenet/src/freenet/support/io/ReadOnlyFileSliceBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/ReadOnlyFileSliceBucket.java   
2006-07-25 16:18:57 UTC (rev 9752)
+++ trunk/freenet/src/freenet/support/io/ReadOnlyFileSliceBucket.java   
2006-07-25 16:48:20 UTC (rev 9753)
@@ -8,11 +8,13 @@
 import java.io.OutputStream;
 import java.io.RandomAccessFile;

+import freenet.support.SimpleFieldSet;

+
 /**
  * FIXME: implement a hash verifying version of this.
  */
-public class ReadOnlyFileSliceBucket implements Bucket {
+public class ReadOnlyFileSliceBucket implements Bucket, 
SerializableToFieldSetBucket {

        private final File file;
        private final long startAt;
@@ -24,6 +26,26 @@
                this.length = length;
        }

+    public ReadOnlyFileSliceBucket(SimpleFieldSet fs) throws 
CannotCreateFromFieldSetException {
+               String tmp = fs.get("Filename");
+               if(tmp == null) throw new CannotCreateFromFieldSetException("No 
filename");
+               this.file = new File(tmp);
+               tmp = fs.get("Length");
+               if(tmp == null) throw new CannotCreateFromFieldSetException("No 
length");
+               try {
+                       length = Long.parseLong(tmp);
+               } catch (NumberFormatException e) {
+                       throw new CannotCreateFromFieldSetException("Corrupt 
length "+tmp, e);
+               }
+               tmp = fs.get("Offset");
+               if(tmp == null) throw new CannotCreateFromFieldSetException("No 
offset");
+               try {
+                       startAt = Long.parseLong(tmp);
+               } catch (NumberFormatException e) {
+                       throw new CannotCreateFromFieldSetException("Corrupt 
offset "+tmp, e);
+               }
+       }
+    
        public OutputStream getOutputStream() throws IOException {
                throw new IOException("Bucket is read-only");
        }
@@ -116,5 +138,14 @@
        public void free() {
                // Do nothing
        }
+
+       public SimpleFieldSet toFieldSet() {
+               SimpleFieldSet fs = new SimpleFieldSet(true);
+               fs.put("Type", "ReadOnlyFileSliceBucket");
+               fs.put("Filename", file.toString());
+               fs.put("Offset", startAt);
+               fs.put("Length", length);
+               return fs;
+       }

 }

Modified: 
trunk/freenet/src/freenet/support/io/SerializableToFieldSetBucketUtil.java
===================================================================
--- trunk/freenet/src/freenet/support/io/SerializableToFieldSetBucketUtil.java  
2006-07-25 16:18:57 UTC (rev 9752)
+++ trunk/freenet/src/freenet/support/io/SerializableToFieldSetBucketUtil.java  
2006-07-25 16:48:20 UTC (rev 9753)
@@ -20,6 +20,8 @@
                        return new NullBucket();
                } else if(type.equals("RandomAccessFileBucket")) {
                        return new RandomAccessFileBucket(fs, f);
+               } else if(type.equals("ReadOnlyFileSliceBucket")) {
+                       return new ReadOnlyFileSliceBucket(fs);
                } else
                        throw new 
CannotCreateFromFieldSetException("Unrecognized type "+type);
        }


Reply via email to