Examples of ZipFile


Examples of java.util.zip.ZipFile

        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

Examples of java.util.zip.ZipFile

         * @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

Examples of java.util.zip.ZipFile

    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

Examples of java.util.zip.ZipFile

    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

Examples of java.util.zip.ZipFile

    }
  }
 
  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

Examples of java.util.zip.ZipFile

  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

Examples of java.util.zip.ZipFile

      nonTermOffsets = nonTerms < 0 ? null : loadOffsetsSuccinctly( basename + NONTERM_OFFSETS_EXTENSION, nonTerms, new File( basename + NONTERMS_EXTENSION ).length() + 1 );

      documentsInputBitStream = documentsByteBufferInputStream != null ? new InputBitStream( documentsByteBufferInputStream ) : new InputBitStream( basename + DOCUMENTS_EXTENSION );
      termsInputStream = new FastBufferedInputStream( termsByteBufferInputStream != null ? termsByteBufferInputStream : new FileInputStream( basename + TERMS_EXTENSION ) );
      nonTermsInputStream = exact ? new FastBufferedInputStream( nonTermsByteBufferInputStream != null ? nonTermsByteBufferInputStream : new FileInputStream( basename + NONTERMS_EXTENSION ) ) : null;
      zipFile = hasNonText ? new ZipFilebasename + ZipDocumentCollection.ZIP_EXTENSION ) : null;
      fileOpenOk = true;
    }
    catch( IOException e ) {
      // We leave the possibility for a filename() to fix the problem and load the right files.
      if ( rethrow ) throw e;
View Full Code Here

Examples of java.util.zip.ZipFile

    public ServiceClassLoader(String path) {
        init(path);
       
        for (File jf : jarFiles) {
            try {
                ZipFile zf = new ZipFile(jf);
                Enumeration<? extends ZipEntry> entries = zf.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = entries.nextElement();
                    String name = entry.getName();
                   
                    if (name.endsWith(".class")) {
View Full Code Here

Examples of java.util.zip.ZipFile

    }

    // Load class or resource from a JAR file
    private byte[] loadFromJar(String jar, String name) {
        BufferedInputStream bis = null;
        ZipFile zf = null;
        try {
            zf = new ZipFile(jar);
            Enumeration<? extends ZipEntry> entries = zf.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.getName().equals(name)) {
                    bis = new BufferedInputStream(zf.getInputStream(entry));
                    int size = (int) entry.getSize();
                    byte[] data = new byte[size];
                    int b = 0, eofFlag = 0;
                    while ((size - b) > 0) {
                        eofFlag = bis.read(data, b, size - b);
                        if (eofFlag == -1)
                            break;
                        b += eofFlag;
                    }
                    return data;
                }
            }
        } catch (Exception e) {
            logger.debug(e, e);
        } finally {
            try {
                if (zf != null)
                    zf.close();
                if (bis != null)
                    bis.close();
            } catch (IOException e) {
                logger.error(e, e);
            }
View Full Code Here

Examples of java.util.zip.ZipFile

    public void run() {
        try {
           
            client.notifyNewTask();
           
            ZipFile zf = new ZipFile(file);
   
                Collection<ModuleJar> modules = new ArrayList<ModuleJar>();
                Map<String, Collection<DcImageIcon>> icons = new HashMap<String, Collection<DcImageIcon>>();
                Map<String, File> data = new HashMap<String, File>();
               
                Enumeration<? extends ZipEntry> list = zf.entries();
               
                client.notifyStarted(zf.size());
                while (list.hasMoreElements() && !canceled) {
                    ZipEntry ze = list.nextElement();
   
                    BufferedInputStream bis = new BufferedInputStream(zf.getInputStream(ze));
                    String name = ze.getName();
                   
                    client.notifyMessage(DcResources.getText("msgProcessingFileX", name));
                   
                    if (name.toLowerCase().endsWith(".xsl")) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.