Package de.schlichtherle.util.zip

Examples of de.schlichtherle.util.zip.ZipFile


     */
    public TrueZipMcRegionChunkStore(File zipFile, String folder) throws IOException, ZipException {
        this.zipFile = zipFile;
        this.folder = folder;

        zip = new ZipFile(zipFile);
    }
View Full Code Here


     * @throws ZipException
     */
    public TrueZipMcRegionChunkStore(File zipFile) throws IOException, ZipException {
        this.zipFile = zipFile;

        zip = new ZipFile(zipFile);
    }
View Full Code Here

     */
    public TrueZipLegacyChunkStore(File zipFile, String folder) throws IOException, ZipException {
        this.zipFile = zipFile;
        this.folder = folder;

        zip = new ZipFile(zipFile);
    }
View Full Code Here

     * @throws ZipException
     */
    public TrueZipLegacyChunkStore(File zipFile) throws IOException, ZipException {
        this.zipFile = zipFile;

        zip = new ZipFile(zipFile);
    }
View Full Code Here

     * @param prefix the pr�fix for matching test
     * @param dest the dest path
     * @throws IOException
     */
    public static void extract(File zipFile, String prefix, String dest) throws IOException {
      ZipFile zip = new ZipFile(zipFile);
      int prefixLength = prefix.length();
        FileOutputStream fos = null;
        Enumeration entries = zip.entries();
        try {
          while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            if(entry.getName().startsWith(prefix)) {
              InputStream is = null;
              try {
                is = zip.getInputStream(entry, true);
                //if prefixLength == 0 the prefix doesn't design any folder so we do not need to substring the entry name.
                File file = new File(dest + "/" + entry.getName().substring((prefixLength==0)?0:prefixLength+1));
                if (! entry.isDirectory()) {
                  IOHelper.copy(is, file);
                } else {
                  file.mkdirs();
                }
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                if(is != null) {
                  try {is.close();} catch (IOException e) {}            
                }
                if(fos != null) {
                  try {fos.close();} catch (IOException e) {}            
                }
              }
            }
          }     
        } finally {
          zip.close();
        }
    }
View Full Code Here

        }
    }

    public static long getExtractedSize(File zipFile) throws FileNotFoundException, ZipException, IOException {
        long total = 0;
        ZipFile zip = new ZipFile(zipFile);
        Enumeration entries = zip.entries();
        try {
            while (entries.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) entries.nextElement();
                total += entry.getSize();
            }
        } finally {
            zip.close();
        }
        return total;
    }
View Full Code Here

    System.out
        .println("****************sampleObjectAction()************************");
    long gStart = System.currentTimeMillis();
    // Serialize object
    long start = System.currentTimeMillis();
    ZipFile zFileBef = new ZipFile(new File("samplefiles/sample00.docx"));
    StringWriter stringWriter = new StringWriter();
    ObjectOutputStream out = X_STREAM
        .createObjectOutputStream(stringWriter);
    out.writeObject(zFileBef);
    out.close();
    String data = stringWriter.toString();
    System.out.printf("Serialization delay       : %s\n", (System
        .currentTimeMillis() - start));
    // Deserialize object
    start = System.currentTimeMillis();
    StringReader stringReader = new StringReader(data);
    ObjectInputStream in = X_STREAM.createObjectInputStream(stringReader);
    ZipFile zFileAft = (ZipFile) in.readObject();
    System.out.printf("Deserialization delay     : %s\n", (System
        .currentTimeMillis() - start));
    // Check objects validity
    // --Original stream
    start = System.currentTimeMillis();
    InputStream inStreamBef = zFileBef.getInputStream(zFileBef
        .getEntry("word/document.xml"));
    Document coreDocumentBef = SAX_READER.read(inStreamBef);
    System.out.printf("Create XML document delay : %s\n", (System
        .currentTimeMillis() - start));
    // --Deserialized stream
    start = System.currentTimeMillis();
    InputStream inStreamAft = zFileAft.getInputStream(zFileAft
        .getEntry("word/document.xml"));
    Document coreDocumentAft = SAX_READER.read(inStreamAft);
    System.out.printf("Create XML document delay : %s\n", (System
        .currentTimeMillis() - start));
    System.out.printf("Global delay inter        : %s\n", (System
View Full Code Here

            prefixToRemove = prefixToRemove.substring(1);
        }       
        de.schlichtherle.io.File src = new de.schlichtherle.io.File(srcPath);
        int readed = -1;
        byte bytes [] = new byte[1024];
        ZipFile zip = new ZipFile(src);
        Enumeration entries = zip.entries();
        try {
          while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            if(entry.getName().startsWith(prefixToRemove)) {
              InputStream is = null;
              try {
                String newName = entry.getName().substring(prefixToRemove.length());
                if(newName.startsWith("/")) { //$NON-NLS-1$
                  newName = newName.substring(1);
                }
                ZipEntry zipEntryOut = new ZipEntry(prefixToAdd + newName);
                zop.putNextEntry(zipEntryOut);
                is = zip.getInputStream(entry, true);
                while((readed = is.read(bytes)) > 0) {
                  zop.write(bytes, 0, readed);
                }
                zop.closeEntry();
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                try {
                  if(is != null) {
                    is.close();
                  }
                } catch (IOException e) {
                }            
              }
            }
          }
        } finally {
          zip.close();
        }
    }
View Full Code Here

        if (false == targetDir.exists() && false == NioUtils.create(targetDir, false, 3)) {
            throw new ArchiveException(String.format("[%s] not exist and create failed", targetDir.getAbsolutePath()));
        }

        List<File> result = new ArrayList<File>();
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(archiveFile);
            Enumeration entries = zipFile.entries();

            while (entries.hasMoreElements()) {
                // entry
                ZipEntry entry = (ZipEntry) entries.nextElement();
                String entryName = entry.getName();
                // target
                File targetFile = new File(targetDir, entryName);
                NioUtils.create(targetFile.getParentFile(), false, 3);// 尝试创建父路径
                InputStream input = null;
                OutputStream output = null;
                try {
                    output = new FileOutputStream(targetFile);
                    input = zipFile.getInputStream(entry);
                    NioUtils.copy(input, output);
                } finally {
                    IOUtils.closeQuietly(input);
                    IOUtils.closeQuietly(output);
                }
                result.add(targetFile);
            }

        } catch (Exception e) {
            throw new ArchiveException(e);
        } finally {
            if (zipFile != null) {
                try {
                    zipFile.close();
                } catch (IOException ex) {
                }
            }
        }
View Full Code Here

TOP

Related Classes of de.schlichtherle.util.zip.ZipFile

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.