Package java.util.zip

Examples of java.util.zip.ZipFile$Window


        return true;
    }

    public long length(String fileName) {
        try {
            ZipFile file = openZipFile(fileName);
            ZipEntry entry = file.getEntry(getEntryName(fileName));
            return entry == null ? 0 : entry.getSize();
        } catch (IOException e) {
            return 0;
        }
    }
View Full Code Here


                path += "!";
            }
            if (!path.endsWith("/")) {
                path += "/";
            }
            ZipFile file = openZipFile(path);
            String dirName = getEntryName(path);
            String prefix = path.substring(0, path.length() - dirName.length());
            Enumeration<? extends ZipEntry> en = file.entries();
            ArrayList<String> list = New.arrayList();
            while (en.hasMoreElements()) {
                ZipEntry entry = en.nextElement();
                String name = entry.getName();
                if (!name.startsWith(dirName)) {
View Full Code Here

        FileObject file = openFileObject(fileName, "r");
        return new FileObjectInputStream(file);
    }

    public FileObject openFileObject(String fileName, String mode) throws IOException {
        ZipFile file = openZipFile(translateFileName(fileName));
        ZipEntry entry = file.getEntry(getEntryName(fileName));
        if (entry == null) {
            throw new FileNotFoundException(fileName);
        }
        return new FileObjectZip(file, entry);
    }
View Full Code Here

        return fileName;
    }

    private static ZipFile openZipFile(String fileName) throws IOException {
        fileName = translateFileName(fileName);
        return new ZipFile(fileName);
    }
View Full Code Here

        return dir.delete();
    }

    public void unzip(File zip, File dest) throws IOException {
        Enumeration entries;
        ZipFile zipFile;

        zipFile = new ZipFile(zip);

        entries = zipFile.entries();

        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();

            if (entry.isDirectory()) {
                (new File(dest, entry.getName())).mkdirs();
                continue;
            }

            copyInputStream(zipFile.getInputStream(entry),
                    new BufferedOutputStream(new FileOutputStream(new File(dest, entry.getName()))));
        }
        zipFile.close();
    }
View Full Code Here

         * @param file the JAR file
         * @param dir the directory to extract the component to.
         */
        private void unzipComponent(String componentName, File file, File dir) {
            try {
                ZipFile zipFile = new JarFile(file);
                // Ensure that this JAR is a component.
                if (zipFile.getEntry("component.xml") == null) {
                    return;
                }
                dir.mkdir();
                manager.getLog().debug("Extracting component: " + componentName);
                for (Enumeration e=zipFile.entries(); e.hasMoreElements(); ) {
                    JarEntry entry = (JarEntry)e.nextElement();
                    File entryFile = new File(dir, entry.getName());
                    // Ignore any manifest.mf entries.
                    if (entry.getName().toLowerCase().endsWith("manifest.mf")) {
                        continue;
                    }
                    if (!entry.isDirectory()) {
                        entryFile.getParentFile().mkdirs();
                        FileOutputStream out = new FileOutputStream(entryFile);
                        InputStream zin = zipFile.getInputStream(entry);
                        byte [] b = new byte[512];
                        int len = 0;
                        while ( (len=zin.read(b))!= -1 ) {
                            out.write(b,0,len);
                        }
                        out.flush();
                        out.close();
                        zin.close();
                    }
                }
                zipFile.close();
                zipFile = null;
            }
            catch (Exception e) {
                manager.getLog().error(e);
            }
View Full Code Here

    public static void unzipFile(String sSrcFileName, String sDstFileName, long lLen) throws FileNotFoundException, IOException {
        int nBufferSize = 4096;

        FileOutputStream dest = null;
        BufferedInputStream bis = null;
        ZipFile zipFile = null;
        IOException ioe = null;
        byte[] data = null;
        try {
            zipFile = new ZipFile(sSrcFileName + ZIP);
            Enumeration e = zipFile.entries();
            ZipEntry entry = null;
            if (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
            }
            bis = new BufferedInputStream(zipFile.getInputStream(entry));

            dest = new FileOutputStream(sDstFileName);

            data = new byte[nBufferSize];

            writeFully(bis, lLen, dest, nBufferSize, data);
        } catch (IOException e) {
            ioe = e;
            logger.warn(e);
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }

                if (dest != null) {
                    dest.close();
                }

                if (zipFile != null) {
                    zipFile.close();
                }
            } catch (Exception e) {

            }
        }
View Full Code Here

    public static void unzipFile(String sSrcFileName, long lStart, String sDstFileName) throws FileNotFoundException, IOException {
        int nBufferSize = 4096;

        BufferedInputStream bis = null;
        RandomAccessFile out = null;
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(sSrcFileName + ZIP);
            Enumeration e = zipFile.entries();
            ZipEntry entry = null;
            if (e.hasMoreElements()) {
                entry = (ZipEntry) e.nextElement();
            }
            bis = new BufferedInputStream(zipFile.getInputStream(entry));
            bis.skip(lStart);

            out = new RandomAccessFile(sDstFileName, "rw");
            out.seek(lStart);

            byte[] data = new byte[nBufferSize];

            while (true) {
                int nReaded = bis.read(data);
                if (nReaded == -1) {
                    break;
                }

                out.write(data, 0, nReaded);
            }//end while
        } finally {
            try {
                if (out != null) {
                    out.close();
                }

                if (bis != null) {
                    bis.close();
                }

                if (zipFile != null) {
                    zipFile.close();
                }
            } catch (Exception e) {

            }
        }
View Full Code Here

    }
  }
 
  private void initZipFile() {
    try {
      zipFile = new ZipFile( zipFilename );
    }
    // We leave the possibility for a filename() to fix the problem and load the right zipfile.
    catch( Exception e ) {}
  }
View Full Code Here

  public void filename( CharSequence filename ) throws IOException {
    /* If we don't have a zipFile, we try to get it relatively to the basename.
     * We also store the resulting filename, so copy() should work. */
    if ( zipFile == null ) {
      zipFilename = new File( new File( filename.toString() ).getParentFile(), zipFilename ).toString();
      zipFile = new ZipFile( zipFilename );
    }
  }
View Full Code Here

TOP

Related Classes of java.util.zip.ZipFile$Window

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.