Examples of ZipFile


Examples of java.util.zip.ZipFile

  }

  public void unzip() throws Exception {
      if (zipFile == null || !zipFile.isFile())
          return;
      ZipFile zf = new ZipFile(zipFile);
      ZipEntry zipEntry;
      for (Enumeration zipEntries = zf.entries(); zipEntries.hasMoreElements(); saveEntry(
              zf.getInputStream(zipEntry), zipEntry))
          zipEntry = (ZipEntry) zipEntries.nextElement();

      zf.close();
  }
View Full Code Here

Examples of java.util.zip.ZipFile

  public File unzipFileInArchive(String fileName) throws Exception {
      File result = null;
      if (zipFile == null || !zipFile.isFile() || !TextUtils.stringSet(fileName))
          return result;
      boolean fileFound = false;
      ZipFile zf = new ZipFile(zipFile);
      Enumeration zipEntries = zf.entries();
      do {
          if (!zipEntries.hasMoreElements())
              break;
          ZipEntry entry = (ZipEntry) zipEntries.nextElement();
          String entryName = entry.getName();
          if (TextUtils.stringSet(entryName) && entryName.startsWith("/"))
              entryName = entryName.substring(1);
          if (fileName.equals(entryName)) {
              fileFound = true;
              result = saveEntry(zf.getInputStream(entry), entry);
          }
      } while (true);
      if (!fileFound)
          AbstractUnzipper.log.error("The file: " + fileName + " could not be found in the archive: "
                  + zipFile.getAbsolutePath());
      zf.close();
      return result;
  }
View Full Code Here

Examples of java.util.zip.ZipFile

    public void load() throws ModuleUpgradeException, ModuleJarException, InvalidModuleXmlException {
       
        try {
            logger.debug("Loading module JAR " + filename);
           
            ZipFile zf = new ZipFile(DataCrow.moduleDir + filename);

            Map<String, byte[]> content = new HashMap<String, byte[]>();
            Enumeration<? extends ZipEntry> list = zf.entries();
            while (list.hasMoreElements()) {
                ZipEntry ze = list.nextElement();

                BufferedInputStream bis = new BufferedInputStream(zf.getInputStream(ze));
                int size = (int) ze.getSize();
                byte[] bytes = new byte[size];
                bis.read(bytes);
               
                String filename = ze.getName();
                content.put(filename, bytes);
               
                bis.close();
            }       
           
            // first get the XML file
            for (String filename : content.keySet()) {
                if (filename.toLowerCase().endsWith("xml"))
                    module = new XmlModule(content.get(filename));
            }
           
            byte[] icon16 = content.get(module.getIcon16Filename());
            byte[] icon32 = content.get(module.getIcon32Filename());
           
            module.setIcon16(icon16);
            module.setIcon32(icon32);
           
            zf.close();
       
        } catch (ZipException e) {
            throw new ModuleJarException(e, "An error occured while reading zipfile " + filename);
        } catch (NullPointerException e) {
            throw new ModuleJarException(e);
View Full Code Here

Examples of java.util.zip.ZipFile

           
            try {
               
                if (!selection.isFile()) return;
               
                ZipFile zf = new ZipFile(selection);
                ZipEntry ze = zf.getEntry("version.txt");
               
                if (ze != null) {
                    InputStream is = zf.getInputStream(ze);
                    BufferedInputStream bis = new BufferedInputStream(is);
                   
                    StringBuffer sb = new StringBuffer();
                    byte[] b = new byte[4096];
                    for (int n; (n = bis.read(b)) != -1;)
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 static List getClassPathArchiveContents(final URL resource)
    {
        final List contents = new ArrayList();
        if (isArchive(resource))
        {
            final ZipFile archive = getArchive(resource);
            if (archive != null)
            {
                for (final Enumeration entries = archive.entries(); entries.hasMoreElements();)
                {
                    final ZipEntry entry = (ZipEntry)entries.nextElement();
                    contents.add(entry.getName());
                }
            }
View Full Code Here

Examples of java.util.zip.ZipFile

     */
    public static ZipFile getArchive(final URL resource)
    {
        try
        {
            ZipFile archive = null;
            if (resource != null)
            {
                String resourceUrl = resource.toString();
                resourceUrl = resourceUrl.replaceFirst(
                        ARCHIVE_PREFIX,
                        "");
                final int entryPrefixIndex = resourceUrl.indexOf('!');
                if (entryPrefixIndex != -1)
                {
                    resourceUrl = resourceUrl.substring(
                            0,
                            entryPrefixIndex);
                }
                resourceUrl = URLDecoder.decode(new URL(resourceUrl).getFile(), URL_DECODE_ENCODING);
                archive = new ZipFile(resourceUrl);
            }
            return archive;
        }
        catch (final Throwable throwable)
        {
View Full Code Here

Examples of java.util.zip.ZipFile

    if ((args.length>1) && (!args[1].equals(""))) {
      zip = new File(args[1]);
      if (!zip.exists()) zip = null;
     
      try{
        ZipFile zipFile = new ZipFile(zip);
        ZipEntry entry = zipFile.getEntry("jre");
        if (entry==null) zip=null;
        zipFile.close();
      } catch(IOException ioe) {}
    }
    else zip = null;
   
    // Code common with Run class
View Full Code Here

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

Examples of java.util.zip.ZipFile

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