Package org.apache.tools.zip

Examples of org.apache.tools.zip.ZipFile$Entry


     * @return true if the file is signed.
     * @throws IOException on error
     */
    public static boolean isSigned(File zipFile, String name)
        throws IOException {
        ZipFile jarFile = null;
        try {
            jarFile = new ZipFile(zipFile);
            if (null == name) {
                Enumeration entries = jarFile.getEntries();
                while (entries.hasMoreElements()) {
                    String eName = ((ZipEntry) entries.nextElement()).getName();
                    if (eName.startsWith(SIG_START)
                        && eName.endsWith(SIG_END)) {
                        return true;
                    }
                }
                return false;
            }
            boolean shortSig = jarFile.getEntry(SIG_START
                        + name.toUpperCase()
                        + SIG_END) != null;
            boolean longSig = false;
            if (name.length() > SHORT_SIG_LIMIT) {
                longSig = jarFile.getEntry(
                    SIG_START
                    + name.substring(0, SHORT_SIG_LIMIT).toUpperCase()
                    + SIG_END) != null;
            }

View Full Code Here


                prefix += "/";
            }
            addParentDirs(null, prefix, zOut, "", dirMode);
        }

        ZipFile zf = null;
        try {
            boolean dealingWithFiles = false;
            File base = null;

            if (zfs == null || zfs.getSrc(getProject()) == null) {
                dealingWithFiles = true;
                base = fileset.getDir(getProject());
            } else if (zfs instanceof ZipFileSet) {
                zf = new ZipFile(zfs.getSrc(getProject()), encoding);
            }

            for (int i = 0; i < resources.length; i++) {
                String name = null;
                if (fullpath.length() > 0) {
                    name = fullpath;
                } else {
                    name = resources[i].getName();
                }
                name = name.replace(File.separatorChar, '/');

                if ("".equals(name)) {
                    continue;
                }

                if (resources[i].isDirectory()) {
                    if (doFilesonly) {
                        continue;
                    }
                    int thisDirMode = zfs != null && zfs.hasDirModeBeenSet()
                        ? dirMode : getUnixMode(resources[i], zf, dirMode);
                    addDirectoryResource(resources[i], name, prefix,
                                         base, zOut,
                                         dirMode, thisDirMode);

                } else { // !isDirectory

                    addParentDirs(base, name, zOut, prefix, dirMode);

                    if (dealingWithFiles) {
                        File f = FILE_UTILS.resolveFile(base,
                                                        resources[i].getName());

                        if (preservePermissions) {
                            int perms = PermissionsUtils.getPermissions(f);                           
                            // Keep top 3 octals or original fileMode, which are
                            // the flags that aren't related to permissions.                       
                            fileMode = (fileMode & 0777000) | perms;
                        }
                       
                        zipFile(f, zOut, prefix + name, fileMode);
                    } else {
                        int thisFileMode =
                            zfs != null && zfs.hasFileModeBeenSet()
                            ? fileMode : getUnixMode(resources[i], zf, fileMode);     
                        addResource(resources[i], name, prefix,
                                    zOut, thisFileMode, zf,
                                    zfs == null
                                    ? null : zfs.getSrc(getProject()));
                    }
                }
            }
        } finally {
            if (zf != null) {
                zf.close();
            }
        }
    }
View Full Code Here

                prefix += "/";
            }
            addParentDirs(null, prefix, zOut, "", dirMode);
        }

        ZipFile zf = null;
        try {
            boolean dealingWithFiles = false;
            File base = null;

            if (zfs == null || zfs.getSrc(getProject()) == null) {
                dealingWithFiles = true;
                base = fileset.getDir(getProject());
            } else if (zfs instanceof ZipFileSet) {
                zf = new ZipFile(zfs.getSrc(getProject()), encoding);
            }

            for (int i = 0; i < resources.length; i++) {
                String name = null;
                if (fullpath.length() > 0) {
                    name = fullpath;
                } else {
                    name = resources[i].getName();
                }
                name = name.replace(File.separatorChar, '/');

                if ("".equals(name)) {
                    continue;
                }

                if (resources[i].isDirectory()) {
                    if (doFilesonly) {
                        continue;
                    }
                    int thisDirMode = zfs != null && zfs.hasDirModeBeenSet()
                        ? dirMode : getUnixMode(resources[i], zf, dirMode);
                    addDirectoryResource(resources[i], name, prefix,
                                         base, zOut,
                                         dirMode, thisDirMode);

                } else { // !isDirectory

                    addParentDirs(base, name, zOut, prefix, dirMode);

                    if (dealingWithFiles) {
                        File f = FILE_UTILS.resolveFile(base,
                                                        resources[i].getName());
                        zipFile(f, zOut, prefix + name, fileMode);
                    } else {
                        int thisFileMode =
                            zfs != null && zfs.hasFileModeBeenSet()
                            ? fileMode : getUnixMode(resources[i], zf,
                                                     fileMode);
                        addResource(resources[i], name, prefix,
                                    zOut, thisFileMode, zf,
                                    zfs == null
                                    ? null : zfs.getSrc(getProject()));
                    }
                }
            }
        } finally {
            if (zf != null) {
                zf.close();
            }
        }
    }
View Full Code Here

            throw new BuildException("Source " + source.getClass().getName()
                                     + " not supported by this plugin");
        }
        InputStream inputStream = null;
        InputSource inputSource = null;
        ZipFile zf = null;

        try {
            /**
             * SAX 2 style parser used to parse the given file.
             */
            XMLReader parser = JAXPUtils.getNamespaceXMLReader();

            String uri = null;
            if (buildFile != null) {
                uri = FILE_UTILS.toURI(buildFile.getAbsolutePath());
                inputStream = new FileInputStream(buildFile);
            } else {
                uri = url.toString();
                int pling = -1;
                if (uri.startsWith("jar:file")
                    && (pling = uri.indexOf("!/")) > -1) {
                    zf = new ZipFile(org.apache.tools.ant.launch.Locator
                                     .fromJarURI(uri), "UTF-8");
                    inputStream =
                        zf.getInputStream(zf.getEntry(uri.substring(pling + 1)));
                } else {
                    inputStream = url.openStream();
                }
            }

View Full Code Here

  @SuppressWarnings("unchecked")
  public void imoport(File file, CmsSite site) throws IOException {
    String resRoot = site.getResPath();
    String tplRoot = site.getTplPath();
    // 用默认编码或UTF-8编码解压会乱码!windows7的原因吗?
    ZipFile zip = new ZipFile(file, "GBK");
    ZipEntry entry;
    String name;
    String filename;
    File outFile;
    File pfile;
    byte[] buf = new byte[1024];
    int len;
    InputStream is = null;
    OutputStream os = null;
    String solution = null;

    Enumeration<ZipEntry> en = zip.getEntries();
    while (en.hasMoreElements()) {
      name = en.nextElement().getName();
      if (!name.startsWith(RES_EXP)) {
        solution = name.substring(0, name.indexOf("/"));
        break;
      }
    }
    if (solution == null) {
      return;
    }
    en = zip.getEntries();
    while (en.hasMoreElements()) {
      entry = en.nextElement();
      if (!entry.isDirectory()) {
        name = entry.getName();
        log.debug("unzip file:{}", name);
        // 模板还是资源
        if (name.startsWith(RES_EXP)) {
          filename = resRoot + "/" + solution
              + name.substring(RES_EXP.length());
        } else {
          filename = tplRoot + SPT + name;
        }
        log.debug("解压地址:{}", filename);
        outFile = new File(realPathResolver.get(filename));
        pfile = outFile.getParentFile();
        if (!pfile.exists()) {
          pfile.mkdirs();
        }
        try {
          is = zip.getInputStream(entry);
          os = new FileOutputStream(outFile);
          while ((len = is.read(buf)) != -1) {
            os.write(buf, 0, len);
          }
        } finally {
View Full Code Here

    if (!outDir.exists() || overWrite) {
      outDir.mkdir();
    }

    try {
      ZipFile zf = new ZipFile(inZip, "GBK"); // 打开压缩文件
      byte[] buffer = new byte[DECOMPRESS_BUFFER_SIZE]; // 解压缩文件时的缓存区

      Enumeration e = zf.getEntries();
      while (e.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) e.nextElement(); // 保存每次读到的entry的引用
        String path = outDir.getPath() + fileSeparator
            + entry.getName().replace('/', fileSeparator);
        files.add(entry.getName().replace('/', fileSeparator));
        if (entry.isDirectory()) { // 处理目录类型的entry
          createDir(path, false);
        } // if
        else { // 处理文件类型的entry
          createDir(path, true);
          InputStream is = zf.getInputStream(entry); // 得到文件类型entry的输入流
          FileOutputStream os = new FileOutputStream(path); // 解压后的输出文件

          long leftSize = entry.getSize(); // 保存输入流中剩下未读的字节数
          int readSize = 0; // 保存实际每次读入的字节数
          while (leftSize > 0) { // 如果输入流中剩下的字节数大于0则继续读
            readSize = is.read(buffer); // 读入到缓冲区,readSize为实际读入的字节数
            leftSize -= readSize; // 更新输入流中剩下的字节数信息
            os.write(buffer, 0, readSize); // 写入缓冲区内容到输出文件流
          } // while
          os.close();
          is.close();
        } // else
      } // while
      zf.close();
    } catch (IOException ios) {
      ios.printStackTrace();
      throw new IOException("在解压缩文件过程中出现未知错误");
    }
    return files;
View Full Code Here

   * @throws IOException
   */
  public static void unzip(String zipFilePath, String targetPath) throws IOException {
    OutputStream os = null;
    InputStream is = null;
    ZipFile zipFile = null;
    try {
      zipFile = new ZipFile(zipFilePath);
      String directoryPath = "";
      if (null == targetPath || "".equals(targetPath)) {
        directoryPath = zipFilePath.substring(0, zipFilePath.lastIndexOf("."));
      } else {
        directoryPath = targetPath;
      }
      Enumeration entryEnum = zipFile.getEntries();
      if (null != entryEnum) {
        ZipEntry zipEntry = null;
        while (entryEnum.hasMoreElements()) {
          zipEntry = (ZipEntry) entryEnum.nextElement();
          if (zipEntry.isDirectory()) {
            directoryPath = directoryPath + File.separator + zipEntry.getName();
            org.jeecgframework.core.util.LogUtil.info(directoryPath);
            continue;
          }
          if (zipEntry.getSize() > 0) {
            // 文件
            File targetFile = buildFile(directoryPath + File.separator + zipEntry.getName(), false);
            os = new BufferedOutputStream(new FileOutputStream(targetFile));
            is = zipFile.getInputStream(zipEntry);
            byte[] buffer = new byte[4096];
            int readLen = 0;
            while ((readLen = is.read(buffer, 0, 4096)) >= 0) {
              os.write(buffer, 0, readLen);
            }
View Full Code Here

     * @param srcF      the source file
     * @param dir       the destination directory
     */
    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
        ZipFile zf = null;
        FileNameMapper mapper = getMapper();
        if (!srcF.exists()) {
            throw new BuildException("Unable to expand "
                    + srcF
                    + " as the file does not exist",
                    getLocation());
        }
        try {
            zf = new ZipFile(srcF, encoding, scanForUnicodeExtraFields);
            boolean empty = true;
            Enumeration e = zf.getEntries();
            while (e.hasMoreElements()) {
                empty = false;
                ZipEntry ze = (ZipEntry) e.nextElement();
                InputStream is = null;
                log("extracting " + ze.getName(), Project.MSG_DEBUG);
                try {
                    extractFile(fileUtils, srcF, dir,
                                is = zf.getInputStream(ze),
                                ze.getName(), new Date(ze.getTime()),
                                ze.isDirectory(), mapper);
                } finally {
                    FileUtils.close(is);
                }
View Full Code Here

            throw new BuildException("Source " + source.getClass().getName()
                                     + " not supported by this plugin");
        }
        InputStream inputStream = null;
        InputSource inputSource = null;
        ZipFile zf = null;

        try {
            /**
             * SAX 2 style parser used to parse the given file.
             */
            XMLReader parser = JAXPUtils.getNamespaceXMLReader();

            String uri = null;
            if (buildFile != null) {
                uri = FILE_UTILS.toURI(buildFile.getAbsolutePath());
                inputStream = new FileInputStream(buildFile);
            } else {
                uri = url.toString();
                int pling = -1;
                if (uri.startsWith("jar:file")
                    && (pling = uri.indexOf("!/")) > -1) {
                    zf = new ZipFile(org.apache.tools.ant.launch.Locator
                                     .fromJarURI(uri), "UTF-8");
                    inputStream =
                        zf.getInputStream(zf.getEntry(uri.substring(pling + 1)));
                } else {
                    inputStream = url.openStream();
                }
            }

View Full Code Here

     * @return true if the file is signed.
     * @throws IOException on error
     */
    public static boolean isSigned(File zipFile, String name)
        throws IOException {
        ZipFile jarFile = null;
        try {
            jarFile = new ZipFile(zipFile);
            if (null == name) {
                Enumeration entries = jarFile.getEntries();
                while (entries.hasMoreElements()) {
                    String eName = ((ZipEntry) entries.nextElement()).getName();
                    if (eName.startsWith(SIG_START)
                        && eName.endsWith(SIG_END)) {
                        return true;
                    }
                }
                return false;
            }
            name = replaceInvalidChars(name);
            boolean shortSig = jarFile.getEntry(SIG_START
                        + name.toUpperCase()
                        + SIG_END) != null;
            boolean longSig = false;
            if (name.length() > SHORT_SIG_LIMIT) {
                longSig = jarFile.getEntry(
                    SIG_START
                    + name.substring(0, SHORT_SIG_LIMIT).toUpperCase()
                    + SIG_END) != null;
            }

View Full Code Here

TOP

Related Classes of org.apache.tools.zip.ZipFile$Entry

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.