Examples of ZipOutputStream


Examples of com.alimama.mdrill.utils.zip.ZipOutputStream

     * @throws Exception
     */
    public static void zip(FileSystem fs,String sourceFolder1, FileSystem fs2,String zipFilePath2) throws Exception {
        OutputStream out = fs2.create(new Path(zipFilePath2),true);
        BufferedOutputStream bos = new BufferedOutputStream(out);
        ZipOutputStream zos = new ZipOutputStream(bos);
        // 解决中文文件名乱码
        zos.setEncoding(CHINESE_CHARSET);
        Path basePath = null;
        Path src=new Path(sourceFolder1);
        FileStatus f=fs.getFileStatus(src);
        if (f.isDir()) {
            basePath =f.getPath();
        } else {
            basePath = f.getPath().getParent();
        }
        zipFile(fs,f, basePath, zos);
        zos.closeEntry();
        zos.close();
        bos.close();
        out.close();
    }
View Full Code Here

Examples of de.schlichtherle.truezip.zip.ZipOutputStream

          saveFile.getParentFile());
      tempFile.deleteOnExit();

      // Create a ZIP stream writing to the temporary file
      FileOutputStream tempStream = new FileOutputStream(tempFile);
      ZipOutputStream zipStream = new ZipOutputStream(tempStream);

      // Stage 1 - save version and configuration
      currentStage++;
      saveVersion(zipStream);
      saveConfiguration(zipStream);
      if (isCanceled()) {
        zipStream.close();
        tempFile.delete();
        return;
      }

      // Stage 2 - save RawDataFile objects
      currentStage++;
      saveRawDataFiles(zipStream);
      if (isCanceled()) {
        zipStream.close();
        tempFile.delete();
        return;
      }

      // Stage 3 - save PeakList objects
      currentStage++;
      savePeakLists(zipStream);
      if (isCanceled()) {
        zipStream.close();
        tempFile.delete();
        return;
      }

      // Stage 4 - save user parameters
      currentStage++;
      saveUserParameters(zipStream);
      if (isCanceled()) {
        zipStream.close();
        tempFile.delete();
        return;
      }

      // Stage 5 - finish and close the temporary ZIP file
      currentStage++;
      currentSavedObjectName = null;
      zipStream.close();

      // Final check for cancel
      if (isCanceled()) {
        tempFile.delete();
        return;
View Full Code Here

Examples of de.schlichtherle.util.zip.ZipOutputStream

    }
 
    public static void main(String[] args) throws FileNotFoundException, ZipException, IOException {
        File tempFile = new File("c:/test.zip");
        de.schlichtherle.io.File zip = new de.schlichtherle.io.File(tempFile);
        ZipOutputStream zop = new ZipOutputStream(new FileOutputStream(new File(zip.getAbsolutePath())));
        copyIntoAZip("file:d:\\woj\\dl\\jgoodies\\validation\\1.1/validation-1_1.zip!/validation-1.1/src/tutorial/*",
                zop,
                "binaries/");
        zop.close();
    }
View Full Code Here

Examples of flex2.compiler.swc.zip.ZipOutputStream

     * "path", then nulls out "files".
     */
    public void save() throws Exception
    {
        String tmpPath = null;
        ZipOutputStream zos = null;

      try
      {
            assert (out != null) || (path != null) : "Must supply either an output stream or a location";
            if (out != null)
            {
                zos = new ZipOutputStream(out);
            }
            else if (path != null)
            {
                tmpPath = path + ".tmp";
                zos = new ZipOutputStream( new BufferedOutputStream( new FileOutputStream( FileUtil.openFile(tmpPath, true) )));
            }

            for (Map.Entry<String, VirtualFile> mapEntry : files.entrySet())
            {
                VirtualFile f = mapEntry.getValue();
                ZipEntry entry = new ZipEntry(mapEntry.getKey());
                entry.setTime(f.getLastModified());
                zos.putNextEntry( entry );

                BufferedInputStream in = new BufferedInputStream(f.getInputStream());
                FileUtil.streamOutput(in, zos);
                zos.closeEntry();
            }

            zos.close();
            zos = null;

            if ((out == null) && (path != null))
            {
                File tmpFile = new File(tmpPath);
                File file = new File(path);
                if (!FileUtils.renameFile( tmpFile, file ))
                {
                    throw new SwcException.SwcNotRenamed( tmpFile.getAbsolutePath(), file.getAbsolutePath() );
                }
            }

            files = null;
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
        finally
        {
            try
            {
                if (out != null)
                {
                    out.close();
                    out = null;
                }
            }
            catch(IOException ioe)
            {
                // ignore
            }

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

Examples of java.util.zip.ZipOutputStream

    throws ServletException, IOException {

    try {
      response.setContentType("application/zip");

      ZipOutputStream zip =
        new ZipOutputStream(response.getOutputStream());

      // add resources
      Vector beans = Resources.getResourceXmlBeans(this);
      for (int i = 0; i < beans.size(); i++) {
        ResourceXmlBean bean = (ResourceXmlBean) beans.get(i);
        File root =
          new File(
            getServletContext().getRealPath("/"),
            resourcesPath);
        File dir = new File(root, bean.getDirectory());
        File[] files = dir.listFiles();
        for (int k = 0; k < files.length; k++) {
          File file = files[k];
          if (file.isFile()) {
            InputStream in = new FileInputStream(file);
            ZipEntry ze =
              new ZipEntry(
                "resources/"
                  + bean.getId()
                  + "/"
                  + file.getName());
            zip.putNextEntry(ze);

            // Transfer bytes from the file to the ZIP file
            int len;
            while ((len = in.read(buf)) > 0) {
              zip.write(buf, 0, len);
            }

            zip.closeEntry();
            in.close();
          }
        }
      }

      // add images
      File root =
        new File(getServletContext().getRealPath("/"), imagesPath);
      File[] files = root.listFiles();
      for (int k = 0; k < files.length; k++) {
        File file = files[k];
        if (file.isFile()) {
          InputStream in = new FileInputStream(file);
          ZipEntry ze = new ZipEntry("images/" + file.getName());
          zip.putNextEntry(ze);

          // Transfer bytes from the file to the ZIP file
          int len;
          while ((len = in.read(buf)) > 0) {
            zip.write(buf, 0, len);
          }

          zip.closeEntry();
          in.close();
        }
      }

      // add sections
      Mapping.begin();
      Vector sections = Section.listAll();
      Mapping.rollback();
      for (int i = 0; i < sections.size(); i++) {
        Section section = (Section) sections.get(i);
        try {
          URL url =
            new URL(
              frontUrl+"/section/"
                + section.getId()
                + ".html?static=true&nocache=true");
          BufferedReader reader =
            new BufferedReader(
              new InputStreamReader(url.openStream()));
          String content = "<!-- �ON static export -->";
          String line = "";
          while (line != null) {
            line = reader.readLine();
            if (line != null) {
              content += line;
            }
          }

          ZipEntry ze =
            new ZipEntry("section/" + section.getId() + ".html");
          zip.putNextEntry(ze);
          zip.write(content.getBytes());
          zip.closeEntry();
        } catch (Exception e) {
          System.out.println(
            "Static export error, section " + section.getId());
        }
      }

      // add publications
      Mapping.begin();
      Vector publications = Publication.listAll();
      Mapping.rollback();
      for (int i = 0; i < publications.size(); i++) {
        Publication publication = (Publication) publications.get(i);
        try {
          URL url =
            new URL(
              frontUrl+"/publication/"
                + publication.getId()
                + ".html?static=true&nocache=true");
          BufferedReader reader =
            new BufferedReader(
              new InputStreamReader(url.openStream()));
          String content = "<!-- �ON static export -->";
          String line = "";
          while (line != null) {
            line = reader.readLine();
            if (line != null) {
              content += line;
            }
          }
          ZipEntry ze =
            new ZipEntry(
              "publication/" + publication.getId() + ".html");
          zip.putNextEntry(ze);
          zip.write(content.getBytes());
          zip.closeEntry();
        } catch (Exception e) {
          System.out.println(
            "Static export error, publication "
              + publication.getId());
        }
      }

      // add index
      URL url =
        new URL(
          frontUrl+"?static=true&nocache=true");
      BufferedReader reader =
        new BufferedReader(new InputStreamReader(url.openStream()));
      String content = "<!-- �ON static export -->";
      String line = "";
      while (line != null) {
        line = reader.readLine();
        if (line != null) {
          content += line;
        }
      }
      ZipEntry ze = new ZipEntry("section/index.html");
      zip.putNextEntry(ze);
      zip.write(content.getBytes());
      zip.closeEntry();
      ze = new ZipEntry("index.html");
      zip.putNextEntry(ze);
      String redirect =
        "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0;URL=section/index.html\">";
      zip.write(redirect.getBytes());
      zip.closeEntry();

      zip.close();
    } catch (Exception e) {
      throw new ServletException(e);
    }

    response.getOutputStream().flush();
View Full Code Here

Examples of java.util.zip.ZipOutputStream

          manifest.delete();
        }
        transformConfig(config, "/vdb.xsl", new StreamResult(new File(metainf, "vdb.xml")));
        config.delete();
        FileOutputStream out = new FileOutputStream(new File(file.getParent(), fileName + "_70.vdb"));
        ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(out));
        int parentLength = dir.getPath().length();
        addDirectory(dir, zos, parentLength);
        zos.close();
      } finally {
        FileUtils.removeDirectoryAndChildren(dir);
      }
    } else if (ext.endsWith("xml") || ext.endsWith("def")){
      File parent = file.getParentFile();
View Full Code Here

Examples of java.util.zip.ZipOutputStream

        writeDirectoryInfo(doc, filename);
      }
 
      // write it to the file
      OutputStream fs = new BufferedOutputStream(new FileOutputStream(f));
      ZipOutputStream zos = new ZipOutputStream(fs);
      zos.setLevel(9);
     
      try {
  //      writeContentToZipFile(doc, zos);
        storeContent(doc);
        writeHeadersToZipFile(doc, zos);
        writeUrlToZipFile(doc, zos);
        if (links != null) {
          writeLinksToZipFile(links, zos);
        }
      } catch (Throwable e){
        System.out.println(e);
      } finally {
        zos.close();
        fs.close();
        long date = doc.getDateAsMilliSeconds();
        f.setLastModified(date > 0 ? date : System.currentTimeMillis());
      }
    } catch (IOException ioex) {
View Full Code Here

Examples of java.util.zip.ZipOutputStream

    // write content
    File fzip = contentFile(md5, ".zip");
    if (!fzip.exists()) {
      checkStoragePathFor(CONTENT, useFirstCharactersAsDirectories(md5));
      OutputStream fs = new BufferedOutputStream(new FileOutputStream(fzip));
      ZipOutputStream zos = null;
      try {
        zos = new ZipOutputStream(fs);
        zos.setLevel(9);
        writeContentToZipFile(doc, zos);
      } finally {
        if (zos != null) {
          zos.close();
        } else {
          fs.close();
        }
      }
    } else {
View Full Code Here

Examples of java.util.zip.ZipOutputStream

          furnitureResourcesRemoteRelativeUrlBase = "";
        }
      }
    }
   
    ZipOutputStream zipOut = null;
    Map<Content, String> contentEntries = new HashMap<Content, String>();
    File furnitureLibraryFile = new File(furnitureLibraryName);
    File tmpFile = null;
    try {
      tmpFile = File.createTempFile("temp", ".sh3f");
      OutputStream out = new FileOutputStream(tmpFile);
      if (out != null) {
        // Create a zip output on file 
        zipOut = new ZipOutputStream(out);
        // Write furniture description file in first entry
        zipOut.putNextEntry(new ZipEntry(DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY + ".properties"));
        writeFurnitureLibraryProperties(zipOut, furnitureLibrary, furnitureLibraryFile,
            offlineFurnitureLibrary, contentMatchingFurnitureName,
            furnitureResourcesRemoteAbsoluteUrlBase, furnitureResourcesRemoteRelativeUrlBase,
            contentEntries);
        zipOut.closeEntry();
        // Write supported languages description files
        for (String language : furnitureLibrary.getSupportedLanguages()) {
          if (!FurnitureLibrary.DEFAULT_LANGUAGE.equals(language)) {
            zipOut.putNextEntry(new ZipEntry(DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY + "_" + language + ".properties"));
            writeFurnitureLibraryLocalizedProperties(zipOut, furnitureLibrary, language);
            zipOut.closeEntry();
          }
        }       
        // Write Content objects in files
        writeContents(zipOut, offlineFurnitureLibrary, furnitureResourcesLocalDirectory, contentEntries);
        // Finish zip writing
        zipOut.finish();
        zipOut.close();
        zipOut = null;

        copyFile(tmpFile, furnitureLibraryFile);
        tmpFile.delete();
      }
    } catch (IOException ex) {
      throw new RecorderException("Can't save furniture library file " + furnitureLibraryName, ex);
    } finally {
      if (zipOut != null) {
        try {
          zipOut.close();
        } catch (IOException ex) {
          throw new RecorderException("Can't close furniture library file " + furnitureLibraryName, ex);
        }
      }
    }
View Full Code Here

Examples of java.util.zip.ZipOutputStream

      // Write content entries in a separate zipped file, if the file doesn't exist
      File file = new File(furnitureResourcesLocalDirectory, mainEntryDirectory + ".zip");
      if (file.exists()) {
        return;
      }
      zipOut = new ZipOutputStream(new FileOutputStream(file));
      mainEntryDirectory = "";
    } else {
      mainEntryDirectory += "/";
    }
   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.