Package java.util.zip

Examples of java.util.zip.ZipOutputStream


  // ---- weaving

  // FOR TESTING
  public Collection<String> weave(File file) throws IOException {
    OutputStream os = FileUtil.makeOutputStream(file);
    this.zipOutputStream = new ZipOutputStream(os);
    prepareForWeave();
    Collection<String> c = weave(new IClassFileProvider() {

      public boolean isApplyAtAspectJMungersOnly() {
        return false;
View Full Code Here


   *
   * @param file
   * @throws IOException
   */
  public void compress (IVirtualFile file) {
    ZipOutputStream output = null;
    try {
      output = new ZipOutputStream(file.getOutputStream());
      this.compress(output, "");
    } catch (IOException e) {
      throw ThrowableManagerRegistry.caught(e);
    } finally {
      if (output != null) try { output.close(); } catch (IOException e) {
        ThrowableManagerRegistry.caught(e);
      }
    }
  }
View Full Code Here

  public ZipEncoding(String entryName) {
    this.entryName = entryName;
  }

  @Override public OutputStream getEncoderStream(OutputStream target) throws IOException {
    ZipOutputStream output = new ZipOutputStream(target);
    output.putNextEntry(new ZipEntry(entryName));
    return output;
  }
View Full Code Here

        this.file = file;
    }

    public void run() {
        //System.out.println("Save " + dataObject.getName());
        ZipOutputStream zipOut = null;
        boolean useTempFile = false;
        File writeFile = null;
        try {
            Progress.start(progressTicket);
            Progress.setDisplayName(progressTicket, NbBundle.getMessage(SaveTask.class, "SaveTask.name"));
            FileObject fileObject = FileUtil.toFileObject(file);
            writeFile = file;
            if (writeFile.exists()) {
                useTempFile = true;
                String tempFileName = writeFile.getName() + "_temp";
                writeFile = new File(writeFile.getParent(), tempFileName);
            }

            //Stream
            int zipLevel = NbPreferences.forModule(SaveTask.class).getInt(ZIP_LEVEL_PREFERENCE, 9);
            FileOutputStream outputStream = new FileOutputStream(writeFile);
            zipOut = new ZipOutputStream(outputStream);
            zipOut.setLevel(zipLevel);

            zipOut.putNextEntry(new ZipEntry("Project"));
            gephiWriter = new GephiWriter();

            //Create Writer and write project
            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
            outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.FALSE);
            BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(zipOut);
            XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bufferedOutputStream, "UTF-8");
            gephiWriter.writeAll(project, writer);
            writer.close();

            //Close
            zipOut.closeEntry();
            zipOut.finish();
            bufferedOutputStream.close();



            //Clean and copy
            if (useTempFile && !cancel) {
                String name = fileObject.getName();
                String ext = fileObject.getExt();

                //Delete original file
                fileObject.delete();

                //Rename temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                FileLock lock = tempFileObject.lock();
                tempFileObject.rename(lock, name, ext);
                lock.releaseLock();
            } else if (cancel) {
                //Delete temp file
                FileObject tempFileObject = FileUtil.toFileObject(writeFile);
                tempFileObject.delete();
            }
            Progress.finish(progressTicket);
        } catch (Exception ex) {
            ex.printStackTrace();
            if (zipOut != null) {
                try {
                    zipOut.close();
                } catch (IOException ex1) {
                }
            }
            if (useTempFile && writeFile != null) {
                writeFile.delete();
View Full Code Here

      earFileName = null;
    }

    WriteStream archiveStream =  null;
    ZipInputStream zipInputStream = null;
    ZipOutputStream zipOutputStream = null;

    try {
      archiveStream = archivePath.openWrite();
      zipOutputStream = new ZipOutputStream(archiveStream);

      zipInputStream = new ZipInputStream(archiveIs);

      ZipEntry zipEntry = zipInputStream.getNextEntry();

      TreeSet<String> entryNames = new TreeSet<String>();

      int copyCount = 0;

      while (zipEntry != null) {
        if (log.isLoggable(Level.FINEST))
          log.log(Level.FINEST, L.l("jsr88 copying entry {0}", zipEntry));

        entryNames.add(zipEntry.getName());

        zipOutputStream.putNextEntry(zipEntry);

        try {
          for (int ch = zipInputStream.read(); ch != -1; ch = zipInputStream.read())
            zipOutputStream.write(ch);
        } catch (IOException e) {
          // XXX: unexpected end of ZLIB input stream.
          log.log(Level.WARNING, L.l("exception copying entry {0}", zipEntry), e);
        }

        zipEntry = zipInputStream.getNextEntry();

        copyCount++;
      }

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("copied {0} entries", copyCount));

      if (archiveIs.read() != -1) {
        if (log.isLoggable(Level.FINE))
          log.log(Level.FINE, L.l("unexpected data at end of archive"));

        while (archiveIs.read() != -1) {}
      }

      int fileCount = 0;

      for (DeploymentPlan.PlanFile file : plan.getFileList()) {
        String zipEntryName = file.getPath();
        if (zipEntryName.startsWith("/"))
          zipEntryName = zipEntryName.substring(1);

        if (log.isLoggable(Level.FINEST))
          log.log(Level.FINEST, L.l("jsr88 plan file {0} output to {1}", file, zipEntryName));

        if (entryNames.contains(zipEntryName))
          log.log(Level.WARNING, L.l("plan file {0} overwrites existing file", zipEntryName));

        entryNames.add(zipEntryName);

        zipEntry = new ZipEntry(zipEntryName);
        zipOutputStream.putNextEntry(zipEntry);
        file.writeToStream(zipOutputStream);

        fileCount++;
      }

      if (log.isLoggable(Level.FINER))
        log.log(Level.FINER, L.l("created {0} entries from plan", fileCount));

      zipInputStream.close();
      zipInputStream = null;

      zipOutputStream.close();
      zipOutputStream = null;

      archiveStream.close();
      archiveStream = null;
    }
    finally {
      if (zipInputStream != null) {
        try {
          zipInputStream.close();
        }
        catch (Exception ex) {
          log.log(Level.FINER, ex.toString(), ex);
        }
      }

      if (zipOutputStream != null) {
        try {
          zipOutputStream.close();
        }
        catch (Exception ex) {
          log.log(Level.FINER, ex.toString(), ex);
        }
      }
View Full Code Here

    }
    private void injectData(File zipfile, OutputStream out) throws IOException
    {
        ZipFile zip = new ZipFile(zipfile);

        ZipOutputStream zos = new ZipOutputStream(out);

        @SuppressWarnings("unchecked")
        Enumeration<ZipEntry> en = (Enumeration<ZipEntry>) zip.entries();
        while (en.hasMoreElements())
        {
            ZipEntry ze = en.nextElement();
            zos.putNextEntry(new ZipEntry(ze.getName()));
            InputStream is = zip.getInputStream(ze);
            XSSFSheet xSheet=getSheetFromZipEntryName(ze.getName());
            if(xSheet!=null)
            {
                SXSSFSheet sxSheet=getSXSSFSheet(xSheet);
                copyStreamAndInjectWorksheet(is,zos,sxSheet.getWorksheetXMLInputStream());
            }
            else
            {
                copyStream(is, zos);
            }
            is.close();
        }

        zos.close();
    }
View Full Code Here

        System.out.println(input.getAbsolutePath());
        InputStream is = new FileInputStream(input);
        File dir = new File("output");
        dir.mkdirs();
        File file = new File("output/xml.jar");
        ZipOutputStream zos =
            new ZipOutputStream(new FileOutputStream(file));
        zos.putNextEntry(new ZipEntry("log4j.xml"));
        int len;
        byte[] buf = new byte[1024];
        while ((len = is.read(buf)) > 0) {
            zos.write(buf, 0, len);
        }
        zos.closeEntry();
        zos.close();
        URL url = new URL("jar:" + file.toURL() + "!/log4j.xml");
        DOMConfigurator.configure(url);
        assertTrue(file.delete());
        assertFalse(file.exists());
    }
View Full Code Here

    public File pack(File configurationDir) throws IOException {
        File zippedDir = File.createTempFile(configurationDir.getName(), ".zip");

        OutputStream out = new FileOutputStream(zippedDir);
        out = new BufferedOutputStream(out);
        ZipOutputStream zos = new ZipOutputStream(out);
        zip(zos, configurationDir, configurationDir);
        zos.close();

        return zippedDir;
    }
View Full Code Here

     */
    public void testJarURL() throws IOException {
        File dir = new File("output");
        dir.mkdirs();
        File file = new File("output/properties.jar");
        ZipOutputStream zos =
            new ZipOutputStream(new FileOutputStream(file));
        zos.putNextEntry(new ZipEntry(LogManager.DEFAULT_CONFIGURATION_FILE));
        zos.write("log4j.rootLogger=debug".getBytes());
        zos.closeEntry();
        zos.close();
        URL url = new URL("jar:" + file.toURL() + "!/" +
                LogManager.DEFAULT_CONFIGURATION_FILE);
        PropertyConfigurator.configure(url);
        assertTrue(file.delete());
        assertFalse(file.exists());
View Full Code Here

    }

    public static void createZip( List<String> files, File zipName, File basedir )
        throws IOException
    {
        ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zipName ) );

        try
        {
            for ( String file : files )
            {
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.