Package java.util.zip

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


    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

  }

  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

  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

    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

           
            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

    }

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

    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

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

    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

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.