Package java.util.zip

Examples of java.util.zip.ZipOutputStream


            ReferenceContainer<WordReference> container = null;
            if (format.equals("zip")) {
                log.logInfo("Writing Hashlist to ZIP-file: " + targetName + ".zip");
                final ZipEntry zipEntry = new ZipEntry(targetName + ".txt");
                final File file = new File(root, targetName + ".zip");
                final ZipOutputStream bos = new ZipOutputStream(new FileOutputStream(file));
                bos.putNextEntry(zipEntry);
                if(indexContainerIterator != null) {
                    while (indexContainerIterator.hasNext()) {
                        counter++;
                        container = indexContainerIterator.next();
                        bos.write(container.getTermHash());
                        bos.write(serverCore.CRLF);
                        if (counter % 500 == 0) {
                            log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + ASCII.String(container.getTermHash()));
                        }
                    }
                }
                bos.flush();
                bos.close();
            } else {
                log.logInfo("Writing Hashlist to TXT-file: " + targetName + ".txt");
                final File file = new File(root, targetName + ".txt");
                final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
                if(indexContainerIterator != null) {
                    while (indexContainerIterator.hasNext()) {
                        counter++;
                        container = indexContainerIterator.next();
                        bos.write(container.getTermHash());
                        bos.write(serverCore.CRLF);
                        if (counter % 500 == 0) {
                            log.logInfo("Found " + counter + " Hashs until now. Last found Hash: " + ASCII.String(container.getTermHash()));
                        }
                    }
                }
                bos.flush();
                bos.close();
            }
            log.logInfo("Total number of Hashs: " + counter + ". Last found Hash: " + (container == null ? "null" : ASCII.String(container.getTermHash())));
        } catch (final IOException e) {
            log.logSevere("IOException", e);
        }
View Full Code Here


    if (DebugFile.trace) {
      DebugFile.writeln(String.valueOf(nMatches)+" matches found");
      DebugFile.write("\n"+sHtml+"\n");
    }

      ZipOutputStream oZOut = new ZipOutputStream(oOutStrm);
      String sLocalName = sFilePath.substring(sFilePath.replace('\\','/').lastIndexOf('/')+1);
    int iDot = sLocalName.lastIndexOf('.');
    if (iDot>0)
      sLocalName = Gadgets.ASCIIEncode(sLocalName.substring(0, iDot)).toLowerCase()+".html";
      else
        sLocalName = Gadgets.ASCIIEncode(sLocalName).toLowerCase();
    oEntries.add(sLocalName);
      if (DebugFile.trace) DebugFile.writeln("Putting entry "+sLocalName+" into ZIP");
    oZOut.putNextEntry(new ZipEntry(sLocalName));
      StringBufferInputStream oHtml = new StringBufferInputStream(sHtml);
      new StreamPipe().between(oHtml, oZOut);
      oHtml.close();
      oZOut.closeEntry();

      for (String sName : oFiles) {
        String sZipEntryName = sName.substring(sName.replace('\\','/').lastIndexOf('/')+1);
        if (!oEntries.contains(sZipEntryName)) {
          oEntries.add(sZipEntryName);
          if (DebugFile.trace) DebugFile.writeln("Putting entry "+sZipEntryName+" into ZIP");
        oZOut.putNextEntry(new ZipEntry(sZipEntryName));
          if (sName.startsWith("http://") || sName.startsWith("https://") || sName.startsWith("file://") || sBaseHref.length()>0) {
            try {
              new StreamPipe().between(new ByteArrayInputStream(readfilebin(sBaseHref+sName)), oZOut);
            } catch (IOException ioe) {
              if (DebugFile.trace) {
                DebugFile.decIdent();
                DebugFile.writeln("Could not download file "+sName);
              }
            }       
          } else {
            try {
              byte[] aFile = readfilebin(sBasePath+(sName.startsWith("/") ? sName.substring(1) : sName));
              if (null!=aFile) {
                if (aFile.length>0)
                  new StreamPipe().between(new ByteArrayInputStream(aFile), oZOut);
              } else {
                DebugFile.writeln("Could not find file "+sBasePath+(sName.startsWith("/") ? sName.substring(1) : sName));
              }
            } catch (IOException ioe) {
              if (DebugFile.trace) {
          DebugFile.decIdent();
                DebugFile.writeln("Could not download file "+sBasePath+(sName.startsWith("/") ? sName.substring(1) : sName));
              }
            }       
          }
          oZOut.closeEntry();
        } // fi (sName!=sLocalName)
      } // next
      oZOut.close();

    } catch (MalformedPatternException mpe) {
     
    } catch (FTPException ftpe) {
     
View Full Code Here

    }
    if (tempFolder == null) {
      throw new IOException("Couldn't create a temporary folder");
    }
           
    ZipOutputStream zipOut = null;
    try {
      // Write model in an OBJ file
      OBJWriter writer = new OBJWriter(new File(tempFolder, entryName), header, -1);
      writer.writeNode(node);
      writer.close();
      // Create a ZIP file containing temp folder files (OBJ + MTL + texture files)
      zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
      zipOut.setLevel(compressionLevel);
      for (File tempFile : tempFolder.listFiles()) {
        if (tempFile.isFile()) {
          InputStream tempIn = null;
          try {
            zipOut.putNextEntry(new ZipEntry(tempFile.getName()));
            tempIn = new FileInputStream(tempFile);
            byte [] buffer = new byte [8096];
            int size;
            while ((size = tempIn.read(buffer)) != -1) {
              zipOut.write(buffer, 0, size);
            }
            zipOut.closeEntry();
          } finally {
            if (tempIn != null) {
              tempIn.close();
            }
          }         
        }
      }
    } finally {
      if (zipOut != null) {
        zipOut.close();
      }
      // Empty tempFolder
      for (File tempFile : tempFolder.listFiles()) {
        if (tempFile.isFile()) {
          tempFile.delete();
View Full Code Here

   * Writes home in a zipped stream followed by <code>Content</code> objects
   * it points to.
   */
  public void writeHome(Home home) throws IOException {
    // Create a zip output on out stream
    ZipOutputStream zipOut = new ZipOutputStream(this.out);
    zipOut.setLevel(this.compressionLevel);
    checkCurrentThreadIsntInterrupted();
    // Write home in first entry in a file "Home"
    zipOut.putNextEntry(new ZipEntry("Home"));
    // Use an ObjectOutputStream that keeps track of Content objects
    ObjectOutputStream objectOut = new HomeObjectOutputStream(zipOut);
    objectOut.writeObject(home);
    objectOut.flush();
    zipOut.closeEntry();
    // Write Content objects in files "0" to "n"
    for (int i = 0, n = contents.size(); i < n; i++) {
      Content content = contents.get(i);
      String entryNameOrDirectory = String.valueOf(i);
      if (content instanceof ResourceURLContent) {
        writeResourceZipEntries(zipOut, entryNameOrDirectory, (ResourceURLContent)content);
      } else if (content instanceof URLContent
                 && ((URLContent)content).isJAREntry()) {
        URLContent urlContent = (URLContent)content;
        // If content comes from a home stream
        if (urlContent instanceof HomeURLContent) {
          writeHomeZipEntries(zipOut, entryNameOrDirectory, (HomeURLContent)urlContent);           
        } else {
          writeZipEntries(zipOut, entryNameOrDirectory, urlContent);
        }
      } else {
        writeZipEntry(zipOut, entryNameOrDirectory, content);
      }
    } 
    // Finish zip writing
    zipOut.finish();
  }
View Full Code Here

   *            whether or not to delete the original file after the operation is successfuly
   *            completed
   * @return true if everything is ok, false if there was an error
   */
  public static final boolean compressToZip(final String sSource, final String sDest, final boolean bDeleteSourceOnSuccess) {
    ZipOutputStream os = null;
    InputStream is = null;

    try {
      os = new ZipOutputStream(new FileOutputStream(sDest));
      is = new FileInputStream(sSource);

      final byte[] buff = new byte[1024];
      int r;

      String sFileName = sSource;
      if (sFileName.indexOf('/') >= 0)
        sFileName = sFileName.substring(sFileName.lastIndexOf('/') + 1);

      os.putNextEntry(new ZipEntry(sFileName));

      while ((r = is.read(buff)) > 0)
        os.write(buff, 0, r);

      is.close();

      os.flush();
      os.closeEntry();
      os.close();
    } catch (Throwable e) {
      Log.log(Log.WARNING, "lazyj.Utils", "compressToZip : cannot compress '" + sSource + "' to '" + sDest + "' because", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
      return false;
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
          // ignore
        }
      }

      if (os != null) {
        try {
          os.close();
        } catch (IOException ioe) {
          // ignore
        }
      }
    }
View Full Code Here

    }

    // remove system bundle.
    all.remove(Activator.getTargetBC().getBundle(0));

    ZipOutputStream out = null;

    StartLevel sl = (StartLevel)slTracker.getService();

    File jarunpackerFile = new File("../tools/jarunpacker/out/jarunpacker/jarunpacker.jar");

    URL jarunpackerURL = null;

    try {
      jarunpackerURL = getClass().getResource("/jarunpacker.jar");
    } catch (Exception ignored) {
    }

    InputStream jarunpacker_in = null;

    try {
      if(file.getName().endsWith(".jar")) {


        if(jarunpackerURL != null) {
          jarunpacker_in = jarunpackerURL.openStream();
        } else if(jarunpackerFile.exists()) {
          jarunpacker_in = new FileInputStream(jarunpackerFile);
        }

        if(jarunpacker_in != null) {
          // Construct a string version of a manifest
          StringBuffer sb = new StringBuffer();
          sb.append("Manifest-Version: 1.0\n");
          sb.append("Main-class: org.knopflerfish.tools.jarunpacker.Main\n");
          sb.append("jarunpacker-optbutton: base\n");
          sb.append("jarunpacker-destdir: .\n");
          sb.append("knopflerfish-version: " + base + "\n");
          sb.append("jarunpacker-opendir: " + base + "\n");

          // Convert the string to a input stream
          InputStream is = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));
          Manifest mf = new Manifest(is);

          out = new JarOutputStream(new FileOutputStream(file), mf);
        } else {
          out = new JarOutputStream(new FileOutputStream(file));
        }
      } else if(file.getName().endsWith(".zip")) {
        out = new ZipOutputStream(new FileOutputStream(file));
      }

      StringBuffer xargs = new StringBuffer();

      int levelMax = -1;

      int bid = 0;
      int lastLevel = -1;
      for(Iterator it = all.iterator(); it.hasNext(); ) {
        Bundle b   = (Bundle)it.next();
        String loc = b.getLocation();

        bid++;

        URL srcURL = new URL(loc);

        String name = Util.shortLocation(loc);

        ZipEntry entry = new ZipEntry(base + "/" + name);

        int level     = -1;

        try {
          level = sl.getBundleStartLevel(b);
        } catch (Exception ignored) {        }

        levelMax = Math.max(level, levelMax);

        if(level != -1 && level != lastLevel) {
          xargs.append("-initlevel " + level + "\n");
          lastLevel = level;
        }

        xargs.append("-install file:" + name + "\n");

        out.putNextEntry(entry);

        InputStream in = null;
        try {
          in = srcURL.openStream();
          int n = 0;
          while ((n = in.read(buf)) != -1) {
            out.write(buf, 0, n);
          }
        } finally {
          try {
            in.close();
          } catch (Exception ignored) { }
        }
      }

      bid = 0;
      for(Iterator it = all.iterator(); it.hasNext(); ) {
        Bundle b   = (Bundle)it.next();
        bid++;

        if(b.getState() == Bundle.ACTIVE) {
          xargs.append("-start " + bid + "\n");
        }
      }

      if(levelMax != -1) {
        xargs.append("-startlevel " + levelMax + "\n");
      }

      ZipEntry entry = new ZipEntry(base + "/" + "init.xargs");
      out.putNextEntry(entry);
      out.write(xargs.toString().getBytes());

      entry = new ZipEntry(base + "/" + "framework.jar");
      out.putNextEntry(entry);

      InputStream in = null;

      File fwFile = new File("framework.jar");
      if(fwFile.exists()) {
        try {
          in = new FileInputStream(fwFile);
          int n = 0;
          while ((n = in.read(buf)) != -1) {
            out.write(buf, 0, n);
          }
        } finally {
          try {
            in.close();
          } catch (Exception ignored) { }
        }
      } else {
        Activator.log.warn("No framework.jar file found");
      }


      // Copy jarunpacker files, if availbale
      if(jarunpacker_in != null) {
        JarInputStream jar_in = null;

        try {
          jar_in = new JarInputStream(new BufferedInputStream(jarunpacker_in));

          ZipEntry srcEntry;
          while(null != (srcEntry = jar_in.getNextEntry())) {

            // Skip unused files from jarunpacker
            if(srcEntry.getName().startsWith("META-INF") ||
               srcEntry.getName().startsWith("OSGI-OPT")) {
              continue;
            }

            ZipEntry destEntry = new ZipEntry(srcEntry.getName());

            out.putNextEntry(destEntry);

            long nTotal = 0;
            int n = 0;
            while (-1 != (n = jar_in.read(buf, 0, buf.length))) {
              out.write(buf, 0, n);
              nTotal += n;
            }
          }
        } finally {
          try { jar_in.close()} catch (Exception ignored) {  }
        }
      } else {
        Activator.log.warn("No jarunpacker available");
      }
      // end of jarunpacker copy

    } catch (Exception e) {
      showErr("Failed to write to " + file, e);
      Activator.log.error("Failed to write to " + file, e);
    } finally {
      try { out.close(); } catch (Exception ignored) { }
    }


    String txt =
      "Saved deploy archive as\n\n" +
View Full Code Here

      JSFile objFile = new JSFile(pstrPathName);
      if (this.isTarget() == true) {
        if (objFile.exists()) {
          objFile.delete();
        }
        objZipOutputStream = new ZipOutputStream(new FileOutputStream(pstrPathName));
        flgResult = true;
        logger.debug(String.format("Zip-File '%1$s' created", pstrPathName));
      }
      else {
        if (objFile.exists()) {
View Full Code Here

    return null;
  }

  @Override
  public OutputStream getOutputStream(String strFileName) {
    ZipOutputStream objZOS = null;
    ZipEntry objZE = objWorkingDirectory.getEntry(strFileName);
    if (objZE != null) {
      try {
        FileOutputStream objFOS = new FileOutputStream(objWorkingDirectory.getName());
        objZOS = new ZipOutputStream(objFOS);
        objZOS.putNextEntry(objZE);
      }
      catch (Exception e) {
        e.printStackTrace();
        throw new JobSchedulerException();
      }
View Full Code Here

  public void writeZipFile(File directoryToZip, List<File> fileList, FileOutputStream fos) {

    try {
      //FileOutputStream fos = new FileOutputStream(directoryToZip.getName() + ".zip");
      ZipOutputStream zos = new ZipOutputStream(fos);

      for (File file : fileList) {
        if (!file.isDirectory()) { // we only zip files, not directories
          addToZip(directoryToZip, file, zos);
        } else {
//          String zipFilePath = file.getCanonicalPath().substring(directoryToZip.getCanonicalPath().length() + 1,
//              file.getCanonicalPath().length());
//          //log.debug("Writing '" + zipFilePath + "' to zip file");
//          ZipEntry zipEntry = new ZipEntry(zipFilePath);
//          zos.putNextEntry(zipEntry);
        }
      }

      zos.close();
      fos.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
View Full Code Here

 
  // build the jar
  // VFS currently does not support building zip files -> use java's ZipOutputStream
  private void buildJar(String newJar) throws IOException
  {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(newJar ));
    FileSystemManager fsManager = VFS.getManager();
    for (String jar : _jar2class.keySet())
    {
      FileObject jarFile;
      if (jar.endsWith(".jar"))
        jarFile = fsManager.resolveFile( "jar:"+jar );
      else
        jarFile = fsManager.resolveFile( jar );
       
        for (String file : _jar2class.get(jar))
        {
          file = file.replaceAll("\\.", "/");
          file += ".class";
          FileObject f = fsManager.resolveFile(jarFile, file);
          if (f.exists())
            addFile(f, file, out);
          else
            System.out.println("file not found "+f);
       
       
    }
    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.