Global.addFile (zOutStream, f, level, pathPrefix)
private function for adding a single file to the .zip archive

  • Parameter Object:
    java.util.zip.ZipOutputStream
  • Parameter Object:
    instance of java.io.File representing the file to be added
  • Parameter Int:
    compression-level (0-9)
  • Parameter String:
    path of the directory in the archive to which the file should be added (optional)
Sourcecode in /home/hannes/helma/modules/helma/Zip.js:
86:   var addFile = function(zOutStream, f, level, pathPrefix) {
87:           var fInStream = new java.io.BufferedInputStream(new java.io.FileInputStream(f));
88:           buf = new java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, f.length());
89:           fInStream.read(buf, 0, f.length());
90:   
91:           var name = new java.lang.StringBuffer();
92:           if (pathPrefix) {
93:               // append clean pathPrefix to name buffer
94:               var st = new java.util.StringTokenizer(pathPrefix, "\\/");
95:              while (st.hasMoreTokens()) {
96:                  name.append(st.nextToken());
97:                  name.append("/");
98:              }
99:          }
100:          name.append(f.getName());
101:          var entry = new java.util.zip.ZipEntry(name.toString());
102:          entry.setSize(f.length());
103:          entry.setTime(f.lastModified());
104:          zOutStream.setLevel(level);
105:          zOutStream.putNextEntry(entry);
106:          zOutStream.write(buf, 0, buf.length);
107:          zOutStream.closeEntry();
108:          fInStream.close();
109:          return true;
110:      }