Package org.apache.tools.zip

Examples of org.apache.tools.zip.ZipOutputStream


    if (outZip.exists() && !overWrite) {
      throw new IOException("输出文件名已存在");
    }

    try {
      ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(
          outZip.getPath()));
      zout.setEncoding("GBK");
      byte[] buffer = new byte[COMPRESS_BUFFER_SIZE]; // 把缓存区作为参数传入避免多次构造缓存区
      for (int i = 0; i < inFile.length; i++) {
        zipFile(inFile[i].getName(), inFile[i], zout, buffer);
      }
      zout.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
      throw new IOException("在生成压缩文件的过程中出现未知错误");
    }
  }
View Full Code Here


        } else {
          fileName = directory + ".zip";
        }
      }
    }
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(fileName));
    try {
      zip(zos, relativePath, directory);
    } catch (IOException ex) {
      throw ex;
    } finally {
      if (null != zos) {
        zos.close();
      }
    }
    return fileName;
  }
View Full Code Here

                                     + " archive " + zipFile
                                     + ": no files were included.",
                                     getLocation());
        }

        ZipOutputStream zOut = null;
        try {
            if (!skipWriting) {
                log("Building MANIFEST-only jar: "
                    + getDestFile().getAbsolutePath());
            }
            zOut = new ZipOutputStream(new FileOutputStream(getDestFile()));

            zOut.setEncoding(getEncoding());
            if (isCompress()) {
                zOut.setMethod(ZipOutputStream.DEFLATED);
            } else {
                zOut.setMethod(ZipOutputStream.STORED);
            }
            initZipOutputStream(zOut);
            finalizeZipOutputStream(zOut);
        } catch (IOException ioe) {
            throw new BuildException("Could not create almost empty JAR archive"
View Full Code Here

            if (!skipWriting) {
                log(action + archiveType + ": " + zipFile.getAbsolutePath());
            }

            ZipOutputStream zOut = null;
            try {
                if (!skipWriting) {
                    zOut = new ZipOutputStream(zipFile);

                    zOut.setEncoding(encoding);
                    zOut.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
                    zOut.setCreateUnicodeExtraFields(createUnicodeExtraFields.
                                                     getPolicy());
                    zOut.setFallbackToUTF8(fallBackToUTF8);
                    zOut.setMethod(doCompress
                        ? ZipOutputStream.DEFLATED : ZipOutputStream.STORED);
                    zOut.setLevel(level);
                }
                initZipOutputStream(zOut);

                // Add the explicit resource collections to the archive.
                for (int i = 0; i < fss.length; i++) {
                    if (addThem[i].length != 0) {
                        addResources(fss[i], addThem[i], zOut);
                    }
                }

                if (doUpdate) {
                    addingNewFiles = false;
                    ZipFileSet oldFiles = new ZipFileSet();
                    oldFiles.setProject(getProject());
                    oldFiles.setSrc(renamedFile);
                    oldFiles.setDefaultexcludes(false);

                    final int addSize = addedFiles.size();
                    for (int i = 0; i < addSize; i++) {
                        PatternSet.NameEntry ne = oldFiles.createExclude();
                        ne.setName((String) addedFiles.elementAt(i));
                    }
                    DirectoryScanner ds =
                        oldFiles.getDirectoryScanner(getProject());
                    ((ZipScanner) ds).setEncoding(encoding);

                    String[] f = ds.getIncludedFiles();
                    Resource[] r = new Resource[f.length];
                    for (int i = 0; i < f.length; i++) {
                        r[i] = ds.getResource(f[i]);
                    }

                    if (!doFilesonly) {
                        String[] d = ds.getIncludedDirectories();
                        Resource[] dr = new Resource[d.length];
                        for (int i = 0; i < d.length; i++) {
                            dr[i] = ds.getResource(d[i]);
                        }
                        Resource[] tmp = r;
                        r = new Resource[tmp.length + dr.length];
                        System.arraycopy(dr, 0, r, 0, dr.length);
                        System.arraycopy(tmp, 0, r, dr.length, tmp.length);
                    }
                    addResources(oldFiles, r, zOut);
                }
                if (zOut != null) {
                    zOut.setComment(comment);
                }
                finalizeZipOutputStream(zOut);

                // If we've been successful on an update, delete the
                // temporary file
View Full Code Here

                                     + " archive " + zipFile
                                     + ": no files were included.",
                                     getLocation());
        }

        ZipOutputStream zOut = null;
        try {
            if (!skipWriting) {
                log("Building MANIFEST-only jar: "
                    + getDestFile().getAbsolutePath());
            }
            zOut = new ZipOutputStream(getDestFile());

            zOut.setEncoding(getEncoding());
            if (isCompress()) {
                zOut.setMethod(ZipOutputStream.DEFLATED);
            } else {
                zOut.setMethod(ZipOutputStream.STORED);
            }
            initZipOutputStream(zOut);
            finalizeZipOutputStream(zOut);
        } catch (IOException ioe) {
            throw new BuildException("Could not create almost empty JAR archive"
View Full Code Here

    File outputZipParentFile = outputZipFile.getParentFile();
    if (!outputZipParentFile.exists()) {
      outputZipParentFile.mkdirs();
    }

    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
        outputZipFile));
    int len = -1;
    for (int i = 0; i < filePathList.size(); i++) {
      if (filePathList.get(i) != null) {
        FileInputStream in = new FileInputStream(filePathList.get(i));
        out.putNextEntry(new org.apache.tools.zip.ZipEntry(fileNameList
            .get(i)));
        while ((len = in.read(buf)) > 0) {
          out.write(buf, 0, len);
        }
        out.closeEntry();
        in.close();
      }
    }
    out.close();
  }
View Full Code Here

    zipFilePath.append(File.separator).append("batch.zip");

    File aFile = new File(zipFilePath.toString());
    aFile.createNewFile();
    OutputStream os = new FileOutputStream(aFile);
    ZipOutputStream zos = new ZipOutputStream(os);
    String[] arraySelect = allSelects.split(",");
    for (int i = 0; i < arraySelect.length; i++) {
      String aSelect = arraySelect[i];
      if (aSelect == null || aSelect.trim().equals("")) {
        continue;
      }
      BOInstance aInstance = bo.refreshContext(aSelect);
      if (aService != null) {
        try {
          aService.invokeAll();
        } catch (ExedoException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
      // String aFileName = aInstance.getValue("APP_NAME");
      if (aInstance != null) {
        String id_applyid = aInstance.getValue("id_applyid");
        ZipEntry ze = new ZipEntry(id_applyid + ".xml");
        zos.putNextEntry(ze);
        zos.write(DODownLoadFile.outHtmlCode(paneModelUid).getBytes(
            "utf-8"));
        ze.clone();
      }
    }
    zos.close();
    return zipFilePath.toString();

  }
View Full Code Here

                                     + " archive " + zipFile
                                     + ": no files were included.",
                                     getLocation());
        }

        ZipOutputStream zOut = null;
        try {
            if (!skipWriting) {
                log("Building MANIFEST-only jar: "
                    + getDestFile().getAbsolutePath());
            }
            zOut = new ZipOutputStream(new FileOutputStream(getDestFile()));

            zOut.setEncoding(getEncoding());
            if (isCompress()) {
                zOut.setMethod(ZipOutputStream.DEFLATED);
            } else {
                zOut.setMethod(ZipOutputStream.STORED);
            }
            initZipOutputStream(zOut);
            finalizeZipOutputStream(zOut);
        } catch (IOException ioe) {
            throw new BuildException("Could not create almost empty JAR archive"
View Full Code Here

            if (!skipWriting) {
                log(action + archiveType + ": " + zipFile.getAbsolutePath());
            }

            ZipOutputStream zOut = null;
            try {
                if (!skipWriting) {
                    zOut = new ZipOutputStream(zipFile);

                    zOut.setEncoding(encoding);
                    zOut.setUseLanguageEncodingFlag(useLanguageEncodingFlag);
                    zOut.setCreateUnicodeExtraFields(createUnicodeExtraFields.
                                                     getPolicy());
                    zOut.setFallbackToUTF8(fallBackToUTF8);
                    zOut.setMethod(doCompress
                        ? ZipOutputStream.DEFLATED : ZipOutputStream.STORED);
                    zOut.setLevel(level);
                }
                initZipOutputStream(zOut);

                // Add the explicit resource collections to the archive.
                for (int i = 0; i < fss.length; i++) {
                    if (addThem[i].length != 0) {
                        addResources(fss[i], addThem[i], zOut);
                    }
                }

                if (doUpdate) {
                    addingNewFiles = false;
                    ZipFileSet oldFiles = new ZipFileSet();
                    oldFiles.setProject(getProject());
                    oldFiles.setSrc(renamedFile);
                    oldFiles.setDefaultexcludes(false);

                    for (int i = 0; i < addedFiles.size(); i++) {
                        PatternSet.NameEntry ne = oldFiles.createExclude();
                        ne.setName((String) addedFiles.elementAt(i));
                    }
                    DirectoryScanner ds =
                        oldFiles.getDirectoryScanner(getProject());
                    ((ZipScanner) ds).setEncoding(encoding);

                    String[] f = ds.getIncludedFiles();
                    Resource[] r = new Resource[f.length];
                    for (int i = 0; i < f.length; i++) {
                        r[i] = ds.getResource(f[i]);
                    }

                    if (!doFilesonly) {
                        String[] d = ds.getIncludedDirectories();
                        Resource[] dr = new Resource[d.length];
                        for (int i = 0; i < d.length; i++) {
                            dr[i] = ds.getResource(d[i]);
                        }
                        Resource[] tmp = r;
                        r = new Resource[tmp.length + dr.length];
                        System.arraycopy(dr, 0, r, 0, dr.length);
                        System.arraycopy(tmp, 0, r, dr.length, tmp.length);
                    }
                    addResources(oldFiles, r, zOut);
                }
                if (zOut != null) {
                    zOut.setComment(comment);
                }
                finalizeZipOutputStream(zOut);

                // If we've been successful on an update, delete the
                // temporary file
View Full Code Here

    protected boolean createEmptyZip(File zipFile) throws BuildException {
        if (!createEmpty) {
            return true;
        }
       
        ZipOutputStream zOut = null;
        try {
            log("Building MANIFEST-only jar: "
                + getDestFile().getAbsolutePath());
            zOut = new ZipOutputStream(new FileOutputStream(getDestFile()));

            zOut.setEncoding(getEncoding());
            if (isCompress()) {
                zOut.setMethod(ZipOutputStream.DEFLATED);
            } else {
                zOut.setMethod(ZipOutputStream.STORED);
            }
            initZipOutputStream(zOut);
            finalizeZipOutputStream(zOut);
        } catch (IOException ioe) {
            throw new BuildException("Could not create almost empty JAR archive"
                                     + " (" + ioe.getMessage() + ")", ioe,
                                     getLocation());
        } finally {
            // Close the output stream.
            try {
                if (zOut != null) {
                    zOut.close();
                }
            } catch (IOException ex) {
            }
            createEmpty = false;
        }
View Full Code Here

TOP

Related Classes of org.apache.tools.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.