Package java.util.jar

Examples of java.util.jar.JarFile


      File jar = FileUtil.getJarFileFromURL(urlString);

      if (jar != null) {
        try {
          // System.out.println("jar: " + jar.getAbsolutePath());
          JarFile jarFile = new JarFile(jar);
          Enumeration entries = jarFile.entries();
          ArrayList list = new ArrayList(250);
          while (entries.hasMoreElements()) {
            JarEntry jarEntry = (JarEntry) entries.nextElement();
            if (jarEntry.getName().startsWith(bundleFolder)
                && jarEntry.getName().endsWith(extension)) {
View Full Code Here


     * JAR should be ignored, false otherwise
     */
    private void scanJar(JarURLConnection conn, boolean ignore)
                throws JasperException {

        JarFile jarFile = null;
        String resourcePath = conn.getJarFileURL().toString();
        try {
            if (redeployMode) {
                conn.setUseCaches(false);
            }
            jarFile = conn.getJarFile();
            Enumeration entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = (JarEntry) entries.nextElement();
                String name = entry.getName();
                if (!name.startsWith("META-INF/")) continue;
                if (!name.endsWith(".tld")) continue;
                InputStream stream = jarFile.getInputStream(entry);
                try {
                    String uri = getUriFromTld(resourcePath, stream);
                    // Add implicit map entry only if its uri is not already
                    // present in the map
                    if (uri != null && mappings.get(uri) == null) {
                        mappings.put(uri, new String[]{ resourcePath, name });
                    }
                } finally {
                    if (stream != null) {
                        try {
                            stream.close();
                        } catch (Throwable t) {
                            // do nothing
                        }
                    }
                }
            }
        } catch (Exception ex) {
            if (!redeployMode) {
                // if not in redeploy mode, close the jar in case of an error
                if (jarFile != null) {
                    try {
                        jarFile.close();
                    } catch (Throwable t) {
                        // ignore
                    }
                }
            }
            if (!ignore) {
                throw new JasperException(ex);
            }
        } finally {
            if (redeployMode) {
                // if in redeploy mode, always close the jar
                if (jarFile != null) {
                    try {
                        jarFile.close();
                    } catch (Throwable t) {
                        // ignore
                    }
                }
            }
View Full Code Here

    if (debug)
      System.out.println("RAConfig.extractFromJAR(" + jarName +  "," + fileName + ")");
    else if (verbose)
      System.out.println("extract \"" + fileName + "\" from \"" + jarName + "\"");

    JarFile jar = new JarFile(jarName);
    ZipEntry entry = jar.getEntry(fileName);
    if (debug)
      System.out.println("RAConfig.extractFromJAR : entry = " + entry);
    // extract the fileName from jar in the tmp directory.
    if (entry != null)
      createFile(fileName,jar.getInputStream(entry));
    jar.close();
  }
View Full Code Here

   */
  private void loadEntries() {
    mZipFileEntries = new HashMap<String, ZipEntry>();
    try {
      // Open the ZIP file
      JarFile zf = new JarFile(getBase());

      // Enumerate each entry
      for (Enumeration<JarEntry> entries = zf.entries(); entries.hasMoreElements();) {
        ZipEntry entry = entries.nextElement();
        mZipFileEntries.put(entry.getName(), entry);
      }
    } catch (IOException e) {
      // If something goes wrong, reset Theme
View Full Code Here

   * @return InputStream of specific Entry
   */
  protected InputStream getInputStream(String entry) {
    ZipEntry zipEntry = mZipFileEntries.get(entry);
    try {
      return new JarFile(getBase()).getInputStream(zipEntry);
    } catch (IOException e) {
      e.printStackTrace();
    }
    return null;
  }
View Full Code Here

   * @return Image
   */
  protected ImageIcon getImageFromTheme(String image) {
    try {
      ZipEntry zipEntry = mZipFileEntries.get(image);
      InputStream in = new JarFile(getBase()).getInputStream(zipEntry);

      //  Create the byte array to hold the data
      byte[] bytes = new byte[(int)zipEntry.getSize()];
      //  Read in the bytes
      int offset = 0;
View Full Code Here

     */
    private static void recursePathJars(String path, ArrayList paths) {
        try {
           
            // check class path information in jar file
            JarFile jfile = new JarFile(path, false);
            Manifest mfst = jfile.getManifest();
            if (mfst != null) {
               
                // look for class path information from manifest
                Attributes attrs = mfst.getMainAttributes();
                String cpath = (String)attrs.get(Attributes.Name.CLASS_PATH);
View Full Code Here

     
      // get name of jar file with natives from urlList
      String nativeJar = getJarName(urlList[i]);
 
      // open jar file
      JarFile jarFile = new JarFile(path + nativeJar, true);
 
      // get list of files in jar
      Enumeration entities = jarFile.entries();
 
      totalSizeExtract = 0;
      int jarNum = i - (urlList.length - nativeJarCount); // used for progressbar
   
      // calculate the size of the files to extract for progress bar
      while (entities.hasMoreElements()) {
        JarEntry entry = (JarEntry) entities.nextElement();
 
        // skip directories and anything in directories
        // conveniently ignores the manifest
        if (entry.isDirectory() || entry.getName().indexOf('/') != -1) {
          continue;
        }
        totalSizeExtract += entry.getSize();
      }
 
      currentSizeExtract = 0;
 
      // reset point to begining by getting list of file again
      entities = jarFile.entries();
 
      // extract all files from the jar
      while (entities.hasMoreElements()) {
        JarEntry entry = (JarEntry) entities.nextElement();
 
        // skip directories and anything in directories
        // conveniently ignores the manifest
        if (entry.isDirectory() || entry.getName().indexOf('/') != -1) {
          continue;
        }
 
        // check if native file already exists if so delete it to make room for new one
        // useful when using the reload button on the browser
        File f = new File(path + "natives" + File.separator + entry.getName());
        if (f.exists()) {
          if (!f.delete()) {
            continue; // unable to delete file, it is in use, skip extracting it
          }
        }
 
        debug_sleep(1000);
 
        InputStream in = jarFile.getInputStream(jarFile.getEntry(entry.getName()));
        OutputStream out = new FileOutputStream(path + "natives" + File.separator + entry.getName());
 
        int bufferSize;
        byte buffer[] = new byte[65536];
 
        while ((bufferSize = in.read(buffer, 0, buffer.length)) != -1) {
          debug_sleep(10);
          out.write(buffer, 0, bufferSize);
          currentSizeExtract += bufferSize;
 
          // update progress bar
          percentage = 65 + (int)(percentageParts * (jarNum + currentSizeExtract/(float)totalSizeExtract));
          subtaskMessage = "Extracting: " + entry.getName() + " " + ((currentSizeExtract * 100) / totalSizeExtract) + "%";
        }
 
        // validate if the certificate for native file is correct
        validateCertificateChain(certificate, entry.getCertificates());
 
        in.close();
        out.close();
      }
      subtaskMessage = "";
 
      jarFile.close();
 
      // delete native jar as it is no longer needed
      File f = new File(path + nativeJar);
      f.delete();
   
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

      } else if (file.isDirectory())
        findInDirectory(results, rootDir, file, packageName);
  }

  private static void findInJar(List<Class<?>> results, File file, String packageName) {
    JarFile jarFile = null;
    String packagePath = nameToPath(packageName) + "/";
    try {
      jarFile = new JarFile(file);
      Enumeration<JarEntry> en = jarFile.entries();
      while (en.hasMoreElements()) {
        JarEntry je = en.nextElement();
        String name = je.getName();
        if (name.startsWith(packagePath) && name.endsWith(CLASS_FILE)) {
          String className = name.substring(0, name.length() - CLASS_FILE.length());
          try {
            Class<?> clz = Class.forName(pathToName(className));
            results.add(clz);
          } catch (ClassNotFoundException e) {
            log.error("无法获取类:" + className, e.getCause()); // 该错误应该不会出现
          }
        }
      }
    } catch (IOException e) {
      log.error("无法读取 Jar 文件:" + file.getName(), e);
    } finally {
      if (jarFile != null)
        try {
          jarFile.close();
        } catch (IOException e) {
        }
    }
  }
View Full Code Here

TOP

Related Classes of java.util.jar.JarFile

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.