Package java.util.jar

Examples of java.util.jar.JarInputStream


   
    private List<String> getClassNamesInPackage(File jar, String packageName, boolean includeSubPackages) {
        List<String> classes = new ArrayList<String>();

        packageName = packageName.replaceAll("\\.", "/");
        JarInputStream jarIn = null;
        try {           
            jarIn = new JarInputStream(new FileInputStream(jar));
            JarEntry jarEntry = jarIn.getNextJarEntry();
            while (jarEntry != null) {
                if (jarEntry.getName().endsWith(".class")) {
                    String name = jarEntry.getName().replaceAll("/", "\\.");
                    if (!name.contains("$")) {                       
                        name = name.substring(0, name.length() - ".class".length());
                    }
                    if (includeSubPackages) {
                        if (jarEntry.getName().startsWith(packageName)) {
                            classes.add(name);
                        }
                    } else {
                        if (jarEntry.getName().substring(0, jarEntry.getName().lastIndexOf('/')).equals(packageName)) {
                            classes.add(name);
                        }
                    }
                }
                jarEntry = jarIn.getNextJarEntry();
            }
        }
        catch (Exception e) {
            Plugin.getDefault().logError("Error during lookup of classnames for package '" + packageName + "'.", e);
        } finally {
            if (jarIn != null) {
                try {
                    jarIn.close();
                }
                catch (IOException e) {
                }
            }
        }
View Full Code Here


//    }

    private void retrievePackages() {
        List<File> jarFiles = retrieveJarFilesInClasspath(true);       
        for (File jarFile : jarFiles) {
            JarInputStream jarIn = null;
            try {
                jarIn = new JarInputStream(new FileInputStream(jarFile));
                JarEntry jarEntry = jarIn.getNextJarEntry();
                while (jarEntry != null) {
                    if (!jarEntry.isDirectory() && !jarEntry.getName().contains("$") && (jarEntry.getName().endsWith(".class") || jarEntry.getName().endsWith(".java"))) {
                        String packageName = jarEntry.getName().substring(0, jarEntry.getName().lastIndexOf("/"));
                        packageName = packageName.replaceAll("/", "\\.");
                       
                        String className = jarEntry.getName().replaceAll("/", "\\.");
                        if (className.endsWith(".class")) {
                            className = className.substring(0, className.indexOf(".class"));
                        } else if (className.endsWith(".java")) {
                            className = className.substring(0, className.indexOf(".java"));
                        }
                       
                        TMLScriptPackage tmlscriptPackage = _packages.get(packageName);
                        if (tmlscriptPackage == null) {
                            tmlscriptPackage = new TMLScriptPackage(packageName);
                            _packages.put(packageName, tmlscriptPackage);
                        }
                       
                        tmlscriptPackage.getClassnames().add(className);
                        //Set<TMLScriptMethod> constructors = getPublicConstructors(className);
                        //tmlscriptPackage.getConstructors().addAll(constructors);
                   
                    }                  
                    jarEntry = jarIn.getNextJarEntry();
                }
            } catch (Exception e) {
                Plugin.getDefault().logError("Error during package retrival.", e);
            } finally {
                if (jarIn != null) {
                    try {
                        jarIn.close();
                    }
                    catch (IOException e) {
                    }
                }
            }
View Full Code Here

    Set paths = context.getResourcePaths("/WEB-INF/lib/");
    fLogger.fine(paths.toString());
    Iterator iter = paths.iterator();
    while ( iter.hasNext() ) {
      String jarFileName = iter.next().toString();
      JarInputStream jarStream = null;
      try {
        jarStream = new JarInputStream(context.getResourceAsStream(jarFileName));
      }
      catch (IOException ex){
        fLogger.severe("Cannot open jar file (to fetch Specification-Version from the jar Manifest).");
      }
      result.put(jarFileName, fetchSpecNamesAndVersions(jarStream));
View Full Code Here

        String jarf = url.getFile();
        jarf = jarf.substring(0, jarf.indexOf("!"));
        url = new URL(jarf);

        byte buffer[] = new byte[4096];
        JarInputStream jin = new JarInputStream(new FileInputStream(url.getFile()));
        List executes = new ArrayList();


        for (JarEntry entry = jin.getNextJarEntry(); entry != null; entry = jin.getNextJarEntry()) {
            if (entry.isDirectory()) {
                if (!entry.getName().startsWith("META-INF")
                    && !entry.getName().startsWith("celtixinstaller")) {
                    if (verbose) {
                        System.out.println("Making directory: " + entry.getName());
                    }
                    File file = new File(outputDir, entry.getName());
                    file.mkdirs();
                    file.setLastModified(entry.getTime());
                }
            } else if (!entry.getName().startsWith("META-INF")
                       && !entry.getName().startsWith("celtixinstaller")) {

                boolean binary = isBinary(entry.getName().toLowerCase());
                if ((entry.getName().indexOf("/bin/") != -1
                    || entry.getName().indexOf("\\bin\\") != -1)
                    && !entry.getName().toLowerCase().endsWith(".bat")) {
                    executes.add(entry.getName());
                }

                File outFile = new File(outputDir, entry.getName());
                if (binary) {
                    if (verbose) {
                        System.out.println("Installing Binary: " + entry.getName());
                    }
                   
                    OutputStream out = new FileOutputStream(outFile);
                    for (int len = jin.read(buffer); len != -1; len = jin.read(buffer)) {
                        out.write(buffer, 0, len);
                    }
                    out.close();
                } else {
                    if (verbose) {
View Full Code Here

     * Returns the Manifest for the specified JAR file name.
     */
    private static Manifest loadManifest(String fn) {
  try {
      FileInputStream fis = new FileInputStream(fn);
      JarInputStream jis = new JarInputStream(fis, false);
      Manifest man = jis.getManifest();
      jis.close();
      return man;
  } catch (IOException e) {
      return null;
  }
    }
View Full Code Here

      }
      if (!dest.isDirectory())
      {
         throw new IOException("Destination must be a directory.");
      }
      JarInputStream jin = new JarInputStream(in);
      byte[] buffer = new byte[1024];
     
      ZipEntry entry = jin.getNextEntry();
      while (entry != null)
      {
         String fileName = entry.getName();
         if (fileName.charAt(fileName.length() - 1) == '/')
         {
            fileName = fileName.substring(0, fileName.length() - 1);
         }
         if (fileName.charAt(0) == '/')
         {
            fileName = fileName.substring(1);
         }
         if (File.separatorChar != '/')
         {
            fileName = fileName.replace('/', File.separatorChar);
         }
         File file = new File(dest, fileName);
         if (entry.isDirectory())
         {
            // make sure the directory exists
            file.mkdirs();
            jin.closeEntry();
         }
         else
         {
            // make sure the directory exists
            File parent = file.getParentFile();
            if (parent != null && !parent.exists())
            {
               parent.mkdirs();
            }
           
            // dump the file
            OutputStream out = new FileOutputStream(file);
            int len = 0;
            while ((len = jin.read(buffer, 0, buffer.length)) != -1)
            {
               out.write(buffer, 0, len);
            }
            out.flush();
            out.close();
            jin.closeEntry();
            file.setLastModified(entry.getTime());
         }
         entry = jin.getNextEntry();
      }
      /* Explicity write out the META-INF/MANIFEST.MF so that any headers such
      as the Class-Path are see for the unpackaged jar
      */
      Manifest mf = jin.getManifest();
      if (mf != null)
      {
         File file = new File(dest, "META-INF/MANIFEST.MF");
         File parent = file.getParentFile();
         if( parent.exists() == false )
View Full Code Here

   private TargetModuleInfo createDeployment(InputStream moduleArchive, String moduleName) throws IOException
   {
      File tmpFile = File.createTempFile("jboss_deployment_", ".zip");
      log.debug("temporary deployment file: " + tmpFile);

      JarInputStream jis = new JarInputStream(moduleArchive);

      // make sure we don't loose the manifest when creating a new JarOutputStream
      JarOutputStream jos = null;
      FileOutputStream fos = new FileOutputStream(tmpFile);
      Manifest manifest = jis.getManifest();
      if (manifest != null)
         jos = new JarOutputStream(fos, manifest);
      else jos = new JarOutputStream(fos);

      // process all modules
      TargetModuleInfo moduleInfo = new TargetModuleInfo();
      ModuleType moduleType = null;
      JarEntry entry = jis.getNextJarEntry();
      while (entry != null)
      {
         String entryName = entry.getName();

         // only process file entries
         if (entryName.endsWith("/") == false)
         {
            moduleType = ifNotNull(determineModuleType(entryName), moduleType);
           
            // process a sub module
            if (entryName.endsWith(".jar") || entryName.endsWith(".war"))
            {
               File tmpSubModule = processSubModule(entryName, jis);
               FileInputStream fis = new FileInputStream(tmpSubModule);
               JarUtils.addJarEntry(jos, entryName, fis);
               fis.close();
            }
            else
            {
               if (mapDeploymentPlan.get("!/" + entryName) == null)
                  JarUtils.addJarEntry(jos, entryName, jis);
               else log.debug("Skip entry found in deployment plan: " + entryName);
            }
         }

         entry = jis.getNextJarEntry();
      }

      // JBAS-8059: the regular jar didn't show us enough information, lets analyze the deployment plan
      for (String entryName : mapDeploymentPlan.keySet())
      {
View Full Code Here

      FileOutputStream fos = new FileOutputStream(tmpModule);
      JarUtils.copyStream(fos, jis);
      fos.close();

      // now open the copy we just made and copy again entry by entry
      JarInputStream jisModule = new JarInputStream(new FileInputStream(tmpModule));
      File tmpJBossModule = getTempFile("jboss_" + entryName);
      tmpFiles.add(tmpJBossModule);
      JarOutputStream jos = null;
      fos = new FileOutputStream(tmpJBossModule);
      Manifest manifest = jisModule.getManifest();
      if (manifest != null)
         jos = new JarOutputStream(fos, manifest);
      else jos = new JarOutputStream(fos);

      // now copy entry by entry
      JarEntry entry = jisModule.getNextJarEntry();
      while (entry != null)
      {
         String subEntryName = entry.getName();
         if (mapDeploymentPlan.get(entryName + "!/" + subEntryName) == null)
            JarUtils.addJarEntry(jos, subEntryName, jisModule);
         else log.debug("Skip entry found in deployment plan: " + subEntryName);

         entry = jisModule.getNextJarEntry();
      }
      jisModule.close();

      addDeploymentPlanEntry(jos, entryName);

      jos.close();
View Full Code Here

         return dpMap;

      // process the deployment plan
      try
      {
         JarInputStream jarDeploymentPlan = new JarInputStream(deploymentPlan);
         JarEntry entry = jarDeploymentPlan.getNextJarEntry();
         while (entry != null)
         {
            String entryName = entry.getName();
            log.debug("unpack deployment plan entry: " + entryName);

            File tempFile = getTempFile(entryName);
            dpMap.put(entryName, tempFile);

            FileOutputStream out = new FileOutputStream(tempFile);
            JarUtils.copyStream(out, jarDeploymentPlan);
            out.close();

            entry = jarDeploymentPlan.getNextJarEntry();
         }
      }
      finally
      {
         deploymentPlan.close();
View Full Code Here

      try
      {
         is = getFile().openStream();
         if (is instanceof JarInputStream)
         {
            JarInputStream jis = (JarInputStream)is;
            JarOutputStream os = new JarOutputStream(bos);
            JarEntry je = null;
            while ((je = jis.getNextJarEntry()) != null)
            {
               if (filter != null && filter.accept(je.getName()))
               {
                  os.putNextEntry(je);
                  VFSUtils.copyStream(jis, os);
View Full Code Here

TOP

Related Classes of java.util.jar.JarInputStream

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.