Package org.apache.tools.zip

Examples of org.apache.tools.zip.ZipEntry


        logWhenWriting("adding directory " + vPath, Project.MSG_VERBOSE);
        addedDirs.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry (vPath);

            // ZIPs store time with a granularity of 2 seconds, round up
            int millisToAdd = roundUp ? ROUNDUP_MILLIS : 0;

            if (dir != null && dir.isExists()) {
                ze.setTime(dir.getLastModified() + millisToAdd);
            } else {
                ze.setTime(System.currentTimeMillis() + millisToAdd);
            }
            ze.setSize (0);
            ze.setMethod (ZipEntry.STORED);
            // This is faintly ridiculous:
            ze.setCrc (EMPTY_CRC);
            ze.setUnixMode(mode);

            if (extra != null) {
                ze.setExtraFields(extra);
            }

            zOut.putNextEntry(ze);
        }
    }
View Full Code Here


        }

        entries.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry(vPath);
            ze.setTime(lastModified);
            ze.setMethod(doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED);

            /*
             * ZipOutputStream.putNextEntry expects the ZipEntry to
             * know its size and the CRC sum before you start writing
             * the data when using STORED mode - unless it is seekable.
             *
             * This forces us to process the data twice.
             */
            if (!zOut.isSeekable() && !doCompress) {
                long size = 0;
                CRC32 cal = new CRC32();
                if (!in.markSupported()) {
                    // Store data into a byte[]
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                    byte[] buffer = new byte[BUFFER_SIZE];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        bos.write(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in = new ByteArrayInputStream(bos.toByteArray());

                } else {
                    in.mark(Integer.MAX_VALUE);
                    byte[] buffer = new byte[BUFFER_SIZE];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in.reset();
                }
                ze.setSize(size);
                ze.setCrc(cal.getValue());
            }

            ze.setUnixMode(mode);
            ZipExtraField[] extra = getCurrentExtraFields();
            if (extra != null) {
                ze.setExtraFields(extra);
            }

            zOut.putNextEntry(ze);

            byte[] buffer = new byte[BUFFER_SIZE];
View Full Code Here

    }

    private void zipDir(String basePath, File formatDir, ZipOutputStream zipOut) throws IOException {
        for(File f : formatDir.listFiles()) {
            if(f.isFile()) {
                ZipEntry nextExtry = new ZipEntry(basePath + File.separator + f.getName());
                zipOut.putNextEntry(nextExtry );
                FileUtils.copyFile(f, zipOut);
            } else {
                zipDir(basePath + File.separator + f.getName(), f, zipOut);
            }
View Full Code Here

    private int getUnixMode(Resource r, ZipFile zf, int defaultMode)
        throws IOException {

        int unixMode = defaultMode;
        if (zf != null) {
            ZipEntry ze = zf.getEntry(r.getName());
            unixMode = ze.getUnixMode();
            if ((unixMode == 0 || unixMode == UnixStat.DIR_FLAG)
                && !preserve0Permissions) {
                unixMode = defaultMode;
            }
        } else if (r instanceof ArchiveResource) {
View Full Code Here

                             ZipOutputStream zOut, int mode,
                             ZipFile zf, File fromArchive)
        throws IOException {

        if (zf != null) {
            ZipEntry ze = zf.getEntry(r.getName());

            if (ze != null) {
                boolean oldCompress = doCompress;
                if (keepCompression) {
                    doCompress = (ze.getMethod() == ZipEntry.DEFLATED);
                }
                InputStream is = null;
                try {
                    is = zf.getInputStream(ze);
                    zipFile(is, zOut, prefix + name, ze.getTime(),
                            fromArchive, mode, ze.getExtraFields(true));
                } finally {
                    doCompress = oldCompress;
                    FileUtils.close(is);
                }
            }
View Full Code Here

        logWhenWriting("adding directory " + vPath, Project.MSG_VERBOSE);
        addedDirs.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry (vPath);

            // ZIPs store time with a granularity of 2 seconds, round up
            int millisToAdd = roundUp ? ROUNDUP_MILLIS : 0;

            if (dir != null && dir.isExists()) {
                ze.setTime(dir.getLastModified() + millisToAdd);
            } else {
                ze.setTime(System.currentTimeMillis() + millisToAdd);
            }
            ze.setSize (0);
            ze.setMethod (ZipEntry.STORED);
            // This is faintly ridiculous:
            ze.setCrc (EMPTY_CRC);
            ze.setUnixMode(mode);

            if (extra != null) {
                ze.setExtraFields(extra);
            }

            zOut.putNextEntry(ze);
        }
    }
View Full Code Here

        }

        entries.put(vPath, vPath);

        if (!skipWriting) {
            ZipEntry ze = new ZipEntry(vPath);
            ze.setTime(lastModified);
            ze.setMethod(doCompress ? ZipEntry.DEFLATED : ZipEntry.STORED);

            /*
             * ZipOutputStream.putNextEntry expects the ZipEntry to
             * know its size and the CRC sum before you start writing
             * the data when using STORED mode - unless it is seekable.
             *
             * This forces us to process the data twice.
             */
            if (!zOut.isSeekable() && !doCompress) {
                long size = 0;
                CRC32 cal = new CRC32();
                if (!in.markSupported()) {
                    // Store data into a byte[]
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();

                    byte[] buffer = new byte[BUFFER_SIZE];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        bos.write(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in = new ByteArrayInputStream(bos.toByteArray());

                } else {
                    in.mark(Integer.MAX_VALUE);
                    byte[] buffer = new byte[BUFFER_SIZE];
                    int count = 0;
                    do {
                        size += count;
                        cal.update(buffer, 0, count);
                        count = in.read(buffer, 0, buffer.length);
                    } while (count != -1);
                    in.reset();
                }
                ze.setSize(size);
                ze.setCrc(cal.getValue());
            }

            ze.setUnixMode(mode);
            ZipExtraField[] extra = getCurrentExtraFields();
            if (extra != null) {
                ze.setExtraFields(extra);
            }

            zOut.putNextEntry(ze);

            byte[] buffer = new byte[BUFFER_SIZE];
View Full Code Here

   *            父ZipEntry
   * @throws IOException
   */
  private void zip(File srcFile, FilenameFilter filter, ZipEntry pentry,
      String prefix) throws IOException {
    ZipEntry entry;
    if (srcFile.isDirectory()) {
      if (pentry == null) {
        entry = new ZipEntry(srcFile.getName());
      } else {
        entry = new ZipEntry(pentry.getName() + "/" + srcFile.getName());
      }
      File[] files = srcFile.listFiles(filter);
      for (File f : files) {
        zip(f, filter, entry, prefix);
      }
    } else {
      if (pentry == null) {
        entry = new ZipEntry(prefix + srcFile.getName());
      } else {
        entry = new ZipEntry(pentry.getName() + "/" + prefix
            + srcFile.getName());
      }
      FileInputStream in;
      try {
        log.debug("读取文件:{}", srcFile.getAbsolutePath());
View Full Code Here

    public ZipEntry getZipEntry() {
      if (StringUtils.isBlank(parent)) {
        return null;
      } else {
        return new ZipEntry(parent);
      }
    }
View Full Code Here

  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());
View Full Code Here

TOP

Related Classes of org.apache.tools.zip.ZipEntry

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.