Package java.util.zip

Examples of java.util.zip.ZipOutputStream


        try {
            resp.setContentType("application/x-download");
            resp.setHeader("Content-Disposition", "attachment; filename=" + path);

            ZipOutputStream zos = new ZipOutputStream(resp.getOutputStream());
            IPath rootPath = new Path(root);
            zipFiles(files, rootPath, zos, includeLibs);
            if(lib!=null) zipLibs(lib, rootPath, zos, useFullSource);
            zos.close();
            // responseString="OK";

        } catch (IOException e) {
            responseString = "Error creating download file : " + e;
        }
View Full Code Here


    }
    zipFile.close();
  }

  public static void zip(File srcDir, File destFile, FileFilter filter) throws IOException {
    ZipOutputStream out = null;
    try {
      out = new ZipOutputStream(new FileOutputStream(destFile));
      Collection<File> files = FileUtils.listFiles(srcDir, TrueFileFilter.TRUE, TrueFileFilter.TRUE);
      for (File f: files) {
        if (filter==null || filter.accept(f)) {
          FileInputStream in = FileUtils.openInputStream(f);
 
          // Add ZIP entry to output stream.
          out.putNextEntry(new ZipEntry(Util.relativePath(srcDir, f).replace('\\', '/')));
 
          // Transfer bytes from the file to the ZIP file
          IOUtils.copyLarge(in, out);
         
          // Complete the entry
          out.closeEntry();
          IOUtils.closeQuietly(in);
        }
      }

      // Complete the ZIP file
      IOUtils.closeQuietly(out);
    } catch (Throwable t) {
      throw new IOException("Failed to create zip file", t);
    } finally {
      if (out != null) {
        out.flush();
        IOUtils.closeQuietly(out);
      }
    }
  }
View Full Code Here

    public static Object Zip_pack(final Context context, final Scriptable thisObj,
                                  final Object[] args, final Function funcObj) throws Exception {
        final File from = new File(Context.toString(args[0]));
        final File into = new File(Context.toString(args[1]));
        final Collection<File> files = CollectionUtils.transform(RhinoUtils.toCollection((Scriptable) args[2]), FileFunctions.file());
        final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(into));
        try {
            for (final File source : files) {
                final String file = FileUtils.relative(from, source);
                final ZipEntry destination = new ZipEntry(file.replace("\\", "/"));
                out.putNextEntry(destination);
                try {
                    FileUtils.copy(source, out);
                    destination.setTime(source.lastModified());
                } finally {
                    out.closeEntry();
                }
            }
            return into.getPath();
        } finally {
            out.close();
        }
    }
View Full Code Here

   String tempJarName = fromJar.replaceAll(".jar", "")+toJarComp;
   int response = JOptionPane.showOptionDialog(null, "Create file: "+tempJarName+" from "+fromJar+" and "+toJar+ " ?""Confirm toolbox creation",
            JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
   if (response == JOptionPane.OK_OPTION)  {
  
       ZipOutputStream out = new ZipOutputStream(new FileOutputStream(tempJarName)); // this is your "out" variable

// copy the files from the old JAR to the new, but don't close the new JAR yet
ZipEntry inEnt;
while ((inEnt = in.getNextEntry()) != null) {
  ZipEntry outEnt = new ZipEntry(inEnt); // copy size, modification time etc.
  byte[] data = new byte[(int)inEnt.getSize()];
  in.read(data); // read data for this old entry
  in.closeEntry();
  out.putNextEntry(outEnt);
  out.write(data); // copy it to the new entry
  out.closeEntry();
}
in.close();

in = new JarInputStream(new FileInputStream(toJar));
// copy the files from the old JAR to the new, but don't close the new JAR yet
while ((inEnt = in.getNextEntry()) != null) {
  ZipEntry outEnt = new ZipEntry(inEnt); // copy size, modification time etc.
  byte[] data = new byte[(int)inEnt.getSize()];
  in.read(data); // read data for this old entry
  in.closeEntry();
try{
    out.putNextEntry(outEnt);
    out.write(data); // copy it to the new entry
    out.closeEntry();
}
catch (IOException ioe) {
    System.out.println("exception trying to put entry "+outEnt.getName());
    out.closeEntry();
}

}
// and *now* we close the new JAR file.
out.close();
in.close();
    }
// We then delete the old JAR file...
//File origFile = new File(fromJar);
//boolean status = origFile.delete();
View Full Code Here

    Args.isTrue(dir.isDirectory(), "Not a directory: '{}'", dir);

    bytearray = new ByteArrayOutputStream();
    try
    {
      ZipOutputStream out = new ZipOutputStream(bytearray);
      try
      {
        zipDir(dir, out, "", recursive);
      } finally {
        out.close();
      }
    }
    catch (RuntimeException e)
    {
      throw e;
View Full Code Here

    setupDirs();
   
    // make a simple tar:
    final File simpleZip = new File(del, FILE);
    OutputStream os = new FileOutputStream(simpleZip);
    ZipOutputStream tos = new ZipOutputStream(os);
    try {
      ZipEntry ze = new ZipEntry("foo");
      byte[] data = "some-content".getBytes("UTF-8");
      ze.setSize(data.length);
      tos.putNextEntry(ze);
      tos.write(data);
      tos.closeEntry();
      tos.flush();
      tos.finish();
    } finally {
      tos.close();
    }
   
    // successfully untar it into an existing dir:
    FileUtil.unZip(simpleZip, tmp);
    // check result:
View Full Code Here

      }

      ZipMultiDirectoryCompress zipCompress = new ZipMultiDirectoryCompress();
      String directory = dir + s;
      String defaultParentPath = "";
      ZipOutputStream zos = null;
      try
      {
        // 创建一个Zip输出流
        zos = new ZipOutputStream(new FileOutputStream(destFile));
        // 启动压缩进程
        zipCompress.startCompress(zos, defaultParentPath, directory);
      } catch (FileNotFoundException e)
      {
        e.printStackTrace();
      } finally
      {
        try
        {
          if (zos != null)
            zos.close();
        } catch (IOException e)
        {
          e.printStackTrace();
        }
      }
View Full Code Here

    private File writeTestFile() throws Exception {
        File output = new File("target/DependenciesScannerTest-tests.jar");
        output.delete();

        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(output));

        out.putNextEntry(new ZipEntry("org/test/TestA.class"));
        out.closeEntry();
        out.putNextEntry(new ZipEntry("org/test/TestB.class"));
        out.closeEntry();
        out.close();
        return output;
    }
View Full Code Here

    }

  } // END generateTables method

  private void saveTables() throws FileNotFoundException, IOException {
    ZipOutputStream zipStream = new ZipOutputStream(new FileOutputStream(
        HAND_RANKS_FILE));
    zipStream.setLevel(Deflater.BEST_COMPRESSION);
    ZipEntry entry = new ZipEntry("handRanks.ser");
    zipStream.putNextEntry(entry);
    ObjectOutputStream s = new ObjectOutputStream(zipStream);
    s.writeObject(handRanks);
    s.close();
  }
View Full Code Here

            u.p(ex);
        }
    }

    private void saveAsZip(File file) throws IOException {
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
        String dir = file.getName().replace(".leoz", "");
        ZipEntry entry = new ZipEntry(dir+"/leo.xml");
        out.putNextEntry(entry);
        XMLWriter outx = new XMLWriter(new PrintWriter(new OutputStreamWriter(out,"UTF-8")),file.toURI());
        NativeExport export = new NativeExport();
        export.setDelayedImageWriting(true);
        ExportProcessor.process(export, outx, ((SketchDocument)context.getDocument()));
        outx.flush();
        out.closeEntry();

        List images = export.getDelayedImages();
        Map<String,BufferedImage> writtenImages = new HashMap<String,BufferedImage>();
        for(Object i : images) {
            if(i instanceof SImage) {
                SImage image = (SImage) i;
                if(!writtenImages.containsKey(image.getRelativeURL())) {
                    ZipEntry ie = new ZipEntry(dir+"/resources/"+image.getRelativeURL());
                    out.putNextEntry(ie);
                    ImageIO.write(image.getBufferedImage(),"png",out);
                    out.flush();
                    out.closeEntry();
                    writtenImages.put(image.getRelativeURL(),image.getBufferedImage());
                }
            }
            if(i instanceof PatternPaint) {
                PatternPaint paint = (PatternPaint) i;
                if(!writtenImages.containsKey(paint.getRelativeURL())) {
                    u.p("saving the real pattern paint  with relative url " + paint.getRelativeURL());
                    ZipEntry ie = new ZipEntry(dir+"/resources/"+ paint.getRelativeURL());
                    out.putNextEntry(ie);
                    ImageIO.write(paint.getImage(),"png",out);
                    out.flush();
                    out.closeEntry();
                    writtenImages.put(paint.getRelativeURL(),paint.getImage());
                }
            }
        }
        out.close();
    }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.