Package java.util.zip

Examples of java.util.zip.ZipFile


        cb.setBackground(Color.green);
      }
     
      // Extract JRE from installer's ZIP if present => gives feedback
      if (installer.zip!=null) {
        ZipFile zip = new ZipFile(installer.zip);
        ZipEntry entry = zip.getEntry("jre");
       
        // Overkill: entry exists and was checked by the installer main function
        if (entry==null) throw new IOException("Internal Error!");
       
        Enumeration enumEntries = zip.entries();
        while (enumEntries.hasMoreElements()) {
         
          entry = (ZipEntry)enumEntries.nextElement();
          if (!entry.getName().startsWith("jre")) continue;

          File f = new File(location, entry.getName());
          if (entry.isDirectory()) {
            f.mkdirs(); // TODO: handle installation failed
            continue;
          }
          if (f.exists() && (!overwriteAll)) {
            Object[] options = new Object[] {
              Installer.resources.getString("yes"),
              Installer.resources.getString("yesAll"),
              Installer.resources.getString("no"),
              Installer.resources.getString("cancel"),
            };
            int res = JOptionPane.showOptionDialog(
                installer,
                Installer.resources.getString("overwriteFile")+f.getAbsolutePath(),
                Installer.resources.getString("overwriteTitle"),
                JOptionPane.DEFAULT_OPTION,
                JOptionPane.QUESTION_MESSAGE,
                null,
                options,
                options[0]);

            if (res==2) continue;
            if ((res==JOptionPane.CLOSED_OPTION) || (res == 3)) break; // TODO: handle installation failed
            if (res==1) overwriteAll = true;
          }
          long size = entry.getSize();
          if (size!=-1) {
            progress.setIndeterminate(false);
            progress.setMinimum(0);     
            progress.setMaximum((int)size);
            progress.setValue(0);
          }
          else progress.setIndeterminate(true);
          progress.setString(Installer.resources.getString("installingJRE")+" : "+f.getAbsolutePath());
          progress.setStringPainted(true);

          FileOutputStream fos = new FileOutputStream(f);
          InputStream zipStream = zip.getInputStream(entry);
          int nread;
          while ((nread = zipStream.read(data)) !=-1) {
            fos.write(data,0,nread);
            try {
              SwingUtilities.invokeAndWait(new BarUpdater(nread));
            } catch (InterruptedException e1) {
            } catch (InvocationTargetException e1) {
            }
          }
          fos.flush();
          fos.close();
        }
        zip.close();
      }
     
      // Else copy file by file the JRE directory
      else if (installer.jre!=null) {
        progress.setMinimum(0);     
View Full Code Here


          }
        }
      } else { //从zip(jar)文件中查找class文件并读取字节数据
        classFile = base; //注意: class文件是从zip(jar)文件中读取的

        ZipFile zipfile = null;
        try {
          zipfile = new ZipFile(base);
          ZipEntry entry = zipfile.getEntry(zipEntryName);
          if (entry != null)
            classData = loadBytesFromStream(zipfile.getInputStream(entry), entry.getSize());
        } catch (Throwable t) {
          throw new ResourceLoaderException("failed to load zip entry: " + zipEntryName, t);
        } finally {
          if (zipfile != null) {
            try {
              zipfile.close();
            } catch (Throwable t) {
            }
          }
        }
      }
View Full Code Here

                /* File is an ordinary file. */
                if (!isArchive(file)) {
                    /* Not a recognized extension; open it to see if
                     it looks like a valid zip file. */
                    try {
                        ZipFile z = new ZipFile(file);
                        z.close();
                        if (warn) {
                            log.warning(Lint.LintCategory.PATH,
                                    "unexpected.archive.file", file);
                        }
                    } catch (IOException e) {
View Full Code Here

        }

        Archive archive;
        try {

            ZipFile zdir = null;

            boolean usePreindexedCache = false;
            String preindexCacheLocation = null;

            if (!useOptimizedZip) {
                zdir = new ZipFile(zipFileName);
            } else {
                usePreindexedCache = options.isSet("usezipindex");
                preindexCacheLocation = options.get("java.io.tmpdir");
                String optCacheLoc = options.get("cachezipindexdir");
View Full Code Here

    protected ZipFile getZipFile() throws FileSystemException
    {
        if (zipFile == null && this.file.exists())
        {
            ZipFile zipFile = createZipFile(this.file);

            this.zipFile = zipFile;
        }

        return zipFile;
View Full Code Here

    protected ZipFile createZipFile(final File file) throws FileSystemException
    {
        try
        {
            return new ZipFile(file);
        }
        catch (IOException ioe)
        {
            throw new FileSystemException("vfs.provider.zip/open-zip-file.error", file, ioe);
        }
View Full Code Here

        return retval;
    }

    private static Collection<String> getResourcesFromJarFile(File file, Pattern pattern) {
        ArrayList<String> retval = new ArrayList<String>();
        ZipFile zf;
        try {
            zf = new ZipFile(file);
        } catch (ZipException e) {
            return retval;
        } catch (IOException e) {
            return retval;
        }
        Enumeration e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) e.nextElement();
            String fileName = ze.getName();
            boolean accept = pattern.matcher(fileName).matches();
            if (accept) {
                retval.add(fileName);
            }
        }
        try {
            zf.close();
        } catch (IOException e1) {
            throw new Error(e1);
        }
        return retval;
    }
View Full Code Here

   * @throws RegainException If preparing the document failed.
   */
  public void prepare(RawDocument rawDocument) throws RegainException {
    File file = rawDocument.getContentAsFile();
   
    ZipFile zipFile;
    try {
      zipFile = new ZipFile(file);
    }
    catch (IOException exc) {
      throw new RegainException("Opening OpenOffice file failed: " +
          file.getAbsolutePath(), exc);
    }

    // Read the content.xml
    ZipEntry entry = zipFile.getEntry("content.xml");
    InputStream xmlStream = null;
    String content;
    try {
      xmlStream = zipFile.getInputStream(entry);
      content = RegainToolkit.readStringFromStream(xmlStream, "UTF-8");
    }
    catch (IOException exc) {
      throw new RegainException("Reading text from OpenOffice file failed: " +
          file.getAbsolutePath(), exc);
    }
    finally {
      if (xmlStream != null) {
        try { xmlStream.close(); } catch (IOException exc) {}
      }
      try { zipFile.close(); } catch (IOException exc) {}
    }

    // Clean the content from tags
    String cleanedContent = CrawlerToolkit.cleanFromHtmlTags(content);
    setCleanedContent(cleanedContent);
View Full Code Here

           continue;
         }
        
      if (!file.isDirectory() && file.exists() && file.canRead())
      {
        ZipFile zipFile = null;
        try
        {
          zipFile = new ZipFile(file);
        } catch (IOException ex)
        {
          Object[] args = { file.getAbsolutePath(), };
          String msg = s_stringMgr.getString("MyURLClassLoader.errorLoadingFile", args);
          logger.error(msg, ex);
          continue;
        }
        notifyListenersLoadedZipFile(file.getName());

        for (Iterator it = new EnumerationIterator(zipFile.entries()); it.hasNext();)
        {
          Class cls = null;
          String entryName = ((ZipEntry) it.next()).getName();
          String className = Utilities.changeFileNameToClassName(entryName);
          if (className != null)
View Full Code Here

   */
  @Override
  public void copyResourceFromJarFile(String jarFilename, String resourceName, String destinationFile)
    throws ZipException, IOException
  {
    ZipFile appJar = new ZipFile(new File(jarFilename));
    Enumeration<? extends ZipEntry> entries = appJar.entries();
    while (entries.hasMoreElements())
    {
      ZipEntry entry = entries.nextElement();
      String entryName = entry.getName();
      if (entryName.endsWith(resourceName))
      {
        InputStream is = null;
        try {
          FileWrapper destinationFileWrapper = fileWrapperFactory.create(destinationFile);
          is = appJar.getInputStream(entry);
          copyBytesToFile(is, destinationFileWrapper);
        } finally {
          closeInputStream(is);
        }
        break;
View Full Code Here

TOP

Related Classes of java.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.