gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/lava gzz/storm/impl/ZipPool.java test/gzz/s...


From: Benja Fallenstein
Subject: [Gzz-commits] gzz/lava gzz/storm/impl/ZipPool.java test/gzz/s...
Date: Tue, 17 Dec 2002 10:48:35 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Benja Fallenstein <address@hidden>      02/12/17 10:48:35

Modified files:
        lava/gzz/storm/impl: ZipPool.java 
        lava/test/gzz/storm/impl: ZipPool.test 

Log message:
        Anton's ZipPool works

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/gzz/storm/impl/ZipPool.java.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/lava/test/gzz/storm/impl/ZipPool.test.diff?tr1=1.3&tr2=1.4&r1=text&r2=text

Patches:
Index: gzz/lava/gzz/storm/impl/ZipPool.java
diff -u gzz/lava/gzz/storm/impl/ZipPool.java:1.5 
gzz/lava/gzz/storm/impl/ZipPool.java:1.6
--- gzz/lava/gzz/storm/impl/ZipPool.java:1.5    Tue Dec 10 11:10:49 2002
+++ gzz/lava/gzz/storm/impl/ZipPool.java        Tue Dec 17 10:48:35 2002
@@ -2,6 +2,7 @@
 
 import gzz.storm.*;
 import gzz.storm.headers.*;
+import gzz.util.*;
 import java.io.*;
 import java.util.*;
 import java.util.zip.*;
@@ -13,6 +14,10 @@
 
        protected Header822 getEntryHeader(BlockId id) throws IOException {
            String name = "b_" + gzz.util.HexUtil.byteArrToHex(id.getBytes());
+           
+           if(file.getEntry(name) == null)
+               throw new FileNotFoundException(name);
+
            InputStream is = new
 BufferedInputStream(id.getCheckedInputStream(
 file.getInputStream(file.getEntry(name))));
@@ -44,41 +49,10 @@
           }
 
           public void close() throws IOException {
-             File tempFile = gzz.util.TempFileUtil.tmpFile(new File("."));
-              FileOutputStream fos = new FileOutputStream(tempFile);
-             ZipOutputStream zop = new ZipOutputStream(fos);
-              byte[] b = new byte[4096];
-
-             for (Enumeration i = file.entries(); i.hasMoreElements() ;) {
-                  ZipEntry e = (ZipEntry)i.nextElement();
-                 zop.putNextEntry(e);
-                 InputStream is = file.getInputStream(e);
-                  while(true) {
-                     int n = is.read(b);
-                     if(n < 0)
-                         break;
-                     zop.write(b, 0, n);
-                 }
-                 zop.closeEntry();
-            }
-
-            BlockId id = makeIdFromDigest();
-            String name = "b_" + gzz.util.HexUtil.byteArrToHex(id.getBytes());
-             ZipEntry e = new ZipEntry(name);
-
-            zop.putNextEntry(e);
-            zop.write(baos.toByteArray());
-             zop.closeEntry();
-
-             zop.close();
-             
-            file.close();
-             File f = new File(file.getName());
-            f.delete();
-            tempFile.renameTo(f);     
-            file = new ZipFile(f);
-            
-            block = get(id);
+             baos.close();
+             BlockId id = makeIdFromDigest();
+             changeZipFile(null, baos.toByteArray(), id);
+             block = get(id);
           }
        }
 
@@ -90,11 +64,68 @@
                return new ZipBlock(id);
        }
 
+        protected void changeZipFile(BlockId delete, byte[] add, BlockId addId)
+                                                               throws 
IOException {
+                  File tempFile = gzz.util.TempFileUtil.tmpFile(new File("."));
+                  FileOutputStream fos = new FileOutputStream(tempFile);
+                  ZipOutputStream zop = new ZipOutputStream(fos);
+                  byte[] b = new byte[4096];
+                   String deleteName = null;
+
+                  if(delete != null)
+                           deleteName = "b_" +
+                             gzz.util.HexUtil.
+                                byteArrToHex(delete.getBytes());
+
+                   for (Enumeration i = file.entries(); i.hasMoreElements() ;) 
{
+                      ZipEntry e = (ZipEntry)i.nextElement();
+
+                     if(e.getName().equals(deleteName))
+                        continue;
+
+                      zop.putNextEntry(e);
+                     InputStream is = file.getInputStream(e);
+                      while(true) {
+                     int n = is.read(b);
+                     if(n < 0)
+                         break;
+                     zop.write(b, 0, n);
+                     }
+                     zop.closeEntry();
+                  }
+
+                  if(add != null) {
+                      addId.check(add);
+
+                     String name = "b_" +
+                        gzz.util.HexUtil.
+                           byteArrToHex(addId.getBytes());
+
+                     ZipEntry e = new ZipEntry(name);
+
+                     zop.putNextEntry(e);
+                     zop.write(add);
+                      zop.closeEntry();
+                   }
+
+                  zop.close();
+
+                  file.close();
+                  File f = new File(file.getName());
+                  f.delete();
+                  tempFile.renameTo(f);
+                  file = new ZipFile(f);
 
-       public void add(Block b) throws IOException{
        }
 
-       public void delete(Block b) {
+       public void add(Block b) throws IOException {
+           byte[] bytes = CopyUtil.readBytes(b.getRawInputStream());
+           changeZipFile(null, bytes, b.getId());
+       }
+
+       public void delete(Block b) throws IOException {
+          BlockId bid = b.getId();
+          changeZipFile(bid, null, null);
        }
 
        public Set getIds() {
@@ -103,14 +134,14 @@
            for (Enumeration i = file.entries(); i.hasMoreElements() ;) {
                   ZipEntry e = (ZipEntry)i.nextElement();
                   String name = e.getName();
-                 
+
                  if(!name.startsWith("b_"))
                      continue;
 
-                 BlockId id = new BlockId(name.substring(2));
+                 BlockId id = new BlockId("storm:block:" + name.substring(2));
                  result.add(id);
-           }             
-           
+           }
+
            return result;
        }
 
@@ -123,6 +154,6 @@
 
        public BlockOutputStream getBlockOutputStream(Header822 hdr) throws
 IOException{
-           return new ZipBlockOutputStream(new VerbatimHeader822(hdr));        
+           return new ZipBlockOutputStream(new VerbatimHeader822(hdr));
         }
 }
Index: gzz/lava/test/gzz/storm/impl/ZipPool.test
diff -u gzz/lava/test/gzz/storm/impl/ZipPool.test:1.3 
gzz/lava/test/gzz/storm/impl/ZipPool.test:1.4
--- gzz/lava/test/gzz/storm/impl/ZipPool.test:1.3       Mon Nov 25 18:52:50 2002
+++ gzz/lava/test/gzz/storm/impl/ZipPool.test   Tue Dec 17 10:48:35 2002
@@ -19,9 +19,14 @@
 import java, gzz
 
 file = gzz.util.TempFileUtil.tmpFile(java.io.File("."));
+os = java.util.zip.ZipOutputStream(java.io.FileOutputStream(file))
+os.putNextEntry(java.util.zip.ZipEntry("foo"))
+os.closeEntry()
+os.close()
+zipfile = java.util.zip.ZipFile(file)
 
 s = gzz.storm.StormPoolTest()
-p = gzz.storm.impl.ZipPool(file)
+p = gzz.storm.impl.ZipPool(zipfile)
 
 def testNewBlock(): s.testNewBlock(p)
 def testOwnHeader(): s.testOwnHeader(p)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]