Examples of JarInputStream


Examples of java.util.jar.JarInputStream

      {
         log.debug("Processing JAR file: " + jarUrl.toString());
      }

      // Use a JarInputStream to read the archive
      JarInputStream jarStream = null;

      // catch any type of IOException
      try
      {

         // open the JAR stream
         jarStream = new JarInputStream(jarUrl.openStream());

         // Loop over all entries of the archive
         JarEntry jarEntry = null;
         while ((jarEntry = jarStream.getNextJarEntry()) != null)
         {

            // We are only interested in java class files
            if (jarEntry.getName().endsWith(".class"))
            {

               // generate FQCN from entry
               String className = getClassName(jarEntry.getName());

               // check name against PackageFilter
               if (mustProcessClass(className))
               {

                  // analyze this class
                  processClass(className, jarStream, visitor);

               }

            }

         }

      }
      catch (IOException e)
      {
         log.error("Failed to read JAR file: " + jarUrl.toString(), e);
      }
      finally
      {
         // Close the stream if it has been opened
         if (jarStream != null)
         {
            try
            {
               jarStream.close();
            }
            catch (IOException e)
            {
               // ignore IO failures on close
            }
View Full Code Here

Examples of java.util.jar.JarInputStream

  }

  private void buildIndex() {
    index = new HashMap<>();
   
    try (JarInputStream stream = new JarInputStream(getJarStream())) {
      JarEntry next = null;
      int pos = 0;
     
      while ((next = stream.getNextJarEntry()) != null) {
        index.put(next.getName(), pos++);
      }
    } catch (IOException e) {
      e.printStackTrace();
      index = null;
View Full Code Here

Examples of java.util.jar.JarInputStream

    return null;
  }
 
  @Override
  public InputStream getInputStream(URI uri) throws IOException {
    try (JarInputStream stream = new JarInputStream(getJarStream())) {
      if (getEntry(stream, uri.getPath()) != null) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buf = new byte[1024];
        int len;
        while ((len = stream.read(buf)) > 0) {
          out.write(buf, 0, len);
        }
       
        return new ByteArrayInputStream(out.toByteArray());
      }
View Full Code Here

Examples of java.util.jar.JarInputStream

    return index.containsKey(file);
  }

  @Override
  public long lastModified(URI uri) throws IOException {
    try (JarInputStream stream = new JarInputStream(getJarStream())) {
      JarEntry je = getEntry(stream, uri.getPath());
      if (je != null) {
        return je.getTime();
      }
    }
View Full Code Here

Examples of java.util.jar.JarInputStream

    throw new FileNotFoundException(uri.toString());
  }

  @Override
  public boolean isDirectory(URI uri) {
    try (JarInputStream stream = new JarInputStream(getJarStream())) {
      JarEntry je = getEntry(stream, uri.getPath());
      if (je != null) {
        return je.isDirectory();
      }
    } catch (IOException e) {
View Full Code Here

Examples of java.util.jar.JarInputStream

      path = path + "/";
    }

    ArrayList<String> matchedEntries = new ArrayList<String>();

    try (JarInputStream stream = new JarInputStream(getJarStream())) {
      JarEntry je = null;

      while ((je = stream.getNextJarEntry()) != null) {
        String name = je.getName();

        if (name.equals(path)) {
          continue;
        }
View Full Code Here

Examples of java.util.jar.JarInputStream

    return cl;
  }

  @SuppressWarnings("resource")
  private static boolean isLegacyJar(Resource jar) throws IOException {
    JarInputStream jis = new JarInputStream(jar.getInputStream());
    JarEntry entry = null;
    try {
      while ((entry = jis.getNextJarEntry()) != null) {
        String name = entry.getName();
        if (name.startsWith("lib/")) {//|| name.startsWith("classes/")
          return true;
        }
      }
View Full Code Here

Examples of java.util.jar.JarInputStream

  }


  @SuppressWarnings("resource")
  private static void unjar(Resource jar, File baseDir) throws IOException {
    JarInputStream jis = new JarInputStream(jar.getInputStream());
    JarEntry entry = null;
    try {
      while ((entry = jis.getNextJarEntry()) != null) {
        if (!entry.isDirectory()) {
          File file = new File(baseDir, entry.getName());
          if (!file.getParentFile().mkdirs()) {
            if (!file.getParentFile().isDirectory()) {
              throw new IOException("Mkdirs failed to create " + file.getParentFile().toString());
            }
          }
          OutputStream out = new FileOutputStream(file);
          try {
            byte[] buffer = new byte[8192];
            int i;
            while ((i = jis.read(buffer)) != -1) {
              out.write(buffer, 0, i);
            }
          } finally {
            IOUtils.closeStream(out);
          }
View Full Code Here

Examples of java.util.jar.JarInputStream

      IOUtils.closeStream(jis);
    }
  }

  static String mainClass(Resource jar) throws IOException {
    JarInputStream jis = new JarInputStream(jar.getInputStream());
    try {
      Manifest mf = jis.getManifest();
      if (mf != null) {
        String main = mf.getMainAttributes().getValue("Main-Class");
        if (StringUtils.hasText(main)) {
          return main.replace("/", ".");
        }
View Full Code Here

Examples of java.util.jar.JarInputStream

                getLog().warn("Error while opening artifact", e);
            }

            try {
                is.mark(256 * 1024);
                JarInputStream jar = new JarInputStream(is);
                Manifest m = jar.getManifest();
                if (m == null) {
                    throw new IOException("Manifest not present in the first entry of the zip");
                }

                return m;
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.