Package java.util.jar

Examples of java.util.jar.JarInputStream


            .add(dpBuilder.createResource()
                .setResourceProcessorPID("org.apache.felix.deploymentadmin.test.rp1")
                .setUrl(getTestResource("test-config1.xml"))
            );

        JarInputStream jis = new JarInputStream(dpBuilder.generate());
        assertNotNull(jis);

        Manifest manifest = jis.getManifest();
        assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
        assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");

        String filename = getBundleName("rp1");
View Full Code Here


            )
            .add(dpBuilder.createBundleResource()
                .setUrl(getTestBundle("bundle2"))
            );

        JarInputStream jis = new JarInputStream(dpBuilder.generate());
        assertNotNull(jis);

        Manifest manifest = jis.getManifest();
        assertManifestHeader(manifest, "DeploymentPackage-SymbolicName", "dp-test");
        assertManifestHeader(manifest, "DeploymentPackage-Version", "1.0.0");

        String filename = getBundleName("bundle1");
View Full Code Here

        ByteArrayOutputStream output = new ByteArrayOutputStream();
        packager.build(output);
        output.close();

        ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
        JarInputStream jar = new JarInputStream(input);
        try {
            while (true) {
                JarEntry entry = jar.getNextJarEntry();
                if (entry == null) {
                    break;
                }
                entries.add(entry.getName());
            }
        } finally {
            jar.close();
        }
    }
View Full Code Here

    {
     
        String s = "jar:"+__userURL+"TestData/test.zip!/subdir/";
        Resource r = Resource.newResource(s);
        InputStream is = r.getInputStream();       
        JarInputStream jin = new JarInputStream(is);
        assertNotNull(is);
        assertNotNull(jin);
       
    }
View Full Code Here

  out.write(data); // copy it to the new entry
  out.closeEntry();
}
in.close();

in = new JarInputStream(new FileInputStream(toJar));
// copy the files from the old JAR to the new, but don't close the new JAR yet
while ((inEnt = in.getNextEntry()) != null) {
  ZipEntry outEnt = new ZipEntry(inEnt); // copy size, modification time etc.
  byte[] data = new byte[(int)inEnt.getSize()];
  in.read(data); // read data for this old entry
View Full Code Here

        int toolboxIndex = 0;   // the scalaSciToolbox class keeps the name of the .jar file of each toolbox and a Vector that holds the bytecodes of its classes
        scalaExec.scalaLab.scalaSciToolbox  ssciToolbox = new scalaExec.scalaLab.scalaSciToolbox();
        ssciToolbox.toolboxName = jarFileName;
      
        JarEntry je;
  JarInputStream jis = new JarInputStream(new BufferedInputStream  (new FileInputStream(jarFileName)));
 
 
    //  scan first the jar for the file "AvoidClassPatterns.txt" and for the startup code
    while  ((je = jis.getNextJarEntry()) != null)  {
        String nameOfEntry = je.toString();
      
        if (nameOfEntry.contains("AvoidClassPatterns.txt"))  {
             patternsToAvoid = readTextFromJar(jarFileName, nameOfEntry);    // get the patterns to avoid from the .jar file
             StringTokenizer strTok = new StringTokenizer(patternsToAvoid, " \n,\t;");
             numOfPatternsToAvoid =strTok.countTokens();
             while (strTok.hasMoreElements()) 
                 avoidClassPatterns.add(strTok.nextToken());
             break;
         }
       
    }
 
 
  jis.close();
  jis = new JarInputStream(new BufferedInputStream  (new FileInputStream(jarFileName)));
    while ((je = jis.getNextJarEntry()) != null)
      {   // while jar file has entries unprocessed
       String nameOfEntry = je.toString();
     
         if (nameOfEntry.contains("startup.ssci"))  {
             startupCode = readTextFromJar(jarFileName, nameOfEntry);    // get the startup code from the .jar file
         }
     
// make sure we have only slashes, i.e. use Unix path conventions
  String name ='/'+je.getName().replace('\\', '/');
 
            String javaName = name.replace('/','.');
            int idx = javaName.lastIndexOf(".class");
            int javaNameLen = javaName.length();
            boolean classStringIsWithinName = javaNameLen > ( idx+".class".length() );
            if (idx != -1 && !classStringIsWithinName) {  // a class file
               javaName = javaName.substring(1, idx);    // remove the first '.'
      
             if (checkAllowed(javaName) == true)   {   // not a class name that we should avoid to load 
               Object  foundClass=null;
              
          try {
                 foundClass = GlobalValues.extensionClassLoader.loadClass(javaName);
          }
             catch (Exception   e) {
                   foundClass = null;
               }
              
            
         boolean classIsPublic = false;
          if (foundClass != null)  {
              int modifier = ((Class) foundClass).getModifiers();
               if (Modifier.isAbstract(modifier)==false && Modifier.isInterface(modifier)== false &&  Modifier.isStatic(modifier)==false)    {  // class is not abstract or interface
                 if ( Modifier.isPublic(modifier) )  {  // class is public
                     classIsPublic = true;
                   ssciToolbox.toolboxClasses.add(foundClass);
                 AutoCompletionScalaSci.scanMethodsScalaSci.add(((Class)foundClass).getName());
                  numJarAutoCompletionItems++;
              if (numJarAutoCompletionItems % 100 == 0) {   // update visual progress
                    dots += ".";
                    String classCntDots = "Classes: "+ numJarAutoCompletionItems+"  "+dots;
                    g2d.clearRect(0, 0, 400, 100);
                    g2d.drawString(classCntDots, 20, 10);
                }
         
         }  // class is public 
                 if (GlobalValues.retrieveAlsoMethods && classIsPublic)  {    // classIsPublic
                     Method [] classMethods=null;
                   try {
             classMethods = ((Class)foundClass).getDeclaredMethods();
            if (classMethods != null)
             if (classMethods.length > 0)
              for (Method currentMethod: classMethods) {
                if (Modifier.isPublic(currentMethod.getModifiers() )) {
                   
                 
                      String methodName = currentMethod.getName()+GlobalValues.smallNameFullPackageSeparator+javaName;
                  if (AutoCompletionScalaSci.scanMethodsScalaSci.indexOf(methodName)==-1) {
                    AutoCompletionScalaSci.scanMethodsScalaSci.add(methodName);
                     numJarAutoCompletionItems++;
                      }
                   }
                   }
                   }
                   catch (SecurityException e) {
                       System.out.println("Security Exception in getDeclaredMethods");
                   }
                     catch (Exception e) {
                         System.out.println("Exception in getDeclaredMethods");
                        
                     }
                   }   // classIsPublic
if (javaName.indexOf("$") == -1) {
      
         String smallName = javaName.substring(javaName.lastIndexOf(".")+1, javaName.length());
        String nameToInsert = smallName+GlobalValues.smallNameFullPackageSeparator+javaName;
        //String elemToInsert = nameToInsert+" #Toolbox  class";
        if (AutoCompletionScalaSci.scanMethodsScalaSci.indexOf(nameToInsert) == -1)   {
           AutoCompletionScalaSci.scanMethodsScalaSci.add(nameToInsert);
           numJarAutoCompletionItems++;
           numJarClasses++;
                        
                      }
                  }     // class is public
               // class is not abstract or interface
           }    // foundClasss != null
           
          
        }   // a class file
            } //
    // while jar file has entries unprocessed
      
  //System.out.println("Found in toolbox "+jarFileName+" #classes = "+JarClassLoader.classesFnt);
// construct a new AutoCompletion Object (needed in order to sort the list of methods, and to permit the access of the new methods)
  scalaExec.Interpreter.GlobalValues.autoCompletionScalaSci = new scalaExec.gui.AutoCompletionScalaSci()// create the autocompletion object
              
jis.close();
System.out.println("number of Toolbox LoadedClasses = "+numJarClasses);
System.out.println("number of Toolbox AutoCompletion Items = "+numJarAutoCompletionItems);
System.out.println("Total items of ScalaSci Autocompletion = "+ scalaExec.Interpreter.GlobalValues.autoCompletionScalaSci.scanMethodsScalaSci.size());
            scalaExec.scalaLab.scalaSciToolboxes.ssciToolboxes.add(ssciToolbox);
View Full Code Here

    Vector  jarClasses = new Vector()
    //  get reference to the global Hashtable that holds all loaded classes
     
   JarEntry je;
  JarInputStream jis = new JarInputStream(new BufferedInputStream  (new FileInputStream(jarFileName)));
  while ((je = jis.getNextJarEntry()) != null)
      {   // while jar file has entries unprocessed
       String nameOfEntry = je.toString();
      
// make sure we have only slashes, i.e. use Unix path conventions
  String name ='/'+je.getName().replace('\\', '/');
 
            String javaName = name.replace('/','.');
            int idx = javaName.lastIndexOf(".class");
            int javaNameLen = javaName.length();
            boolean classStringIsWithinName = javaNameLen > ( idx+".class".length() );
            if (idx != -1 && !classStringIsWithinName) {  // a class file
                javaName = javaName.substring(1, javaNameLen);    // remove the first '.'
      
               jarClasses.add(javaName);
            
        }   // a class file
    // while jar file has entries unprocessed
      
              
jis.close();
  
    return  jarClasses;
}
View Full Code Here

     */
    private static Manifest getManifest(InputStream inStream)
            throws IOException {

        Manifest manifest = null;
        JarInputStream jin = null;

        try {
            jin = new JarInputStream(inStream);
            manifest = jin.getManifest();
            jin.close();
            jin = null;
        } finally {
            if (jin != null) {
                try {
                    jin.close();
                } catch (Throwable t) {
                    // Ignore
                }
            }
        }
View Full Code Here

        boolean changed = false;
        BufferedReader check = null;
        File tmpFile = FILE_UTILS.createTempFile("listfiles", ".out",
                                                 jar.getParentFile());
        // open the jar file and output file
        JarInputStream in = null;
        try {
            in = new JarInputStream(new FileInputStream(jar));
            PrintWriter out = new PrintWriter(new FileWriter(tmpFile));
           
            // open the existing file to see about changes
            if (output.exists()) {
                check = new BufferedReader(new FileReader(output));
            } else {
                changed = true;
            }
           
            Pattern p = Pattern.compile("^" + dir + "/(.+)");
           
            JarEntry je;
            while ((je = in.getNextJarEntry()) != null) {
                Matcher m = p.matcher(je.getName());
                if (m.matches() && m.groupCount() == 1) {
                    String line = "/" + m.group();

                    // see if this is different
                    if (!changed && !line.equals(check.readLine())) {
                        changed = true;
                        check.close();
                    }
                   
                    out.println(line);
                }
            }
           
            out.close();
           
            // overwrite only if the file changed
            if (changed) {
                FILE_UTILS.rename(tmpFile, output);
            } else {
                tmpFile.delete();
            }
        } catch (IOException ioe) {
            throw new BuildException(ioe);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException ioe) {
                    log("Error closing file " + jar, ioe, Project.MSG_WARN);
                }
            }
        }
View Full Code Here

                    }
                   
                    // Do we need to look for a main class?
                    if ($entry.startsWith(MAIN_PREFIX)) {
                        if (mainClass == null) {
                            JarInputStream jis = new JarInputStream(jarFile.getInputStream(entry));
                            Manifest m = jis.getManifest();
                            jis.close();
                            // Is this a jar file with a manifest?
                            if (m != null) {
                                mainClass = jis.getManifest().getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
                                mainJar = $entry;
                            }
                        } else if (mainJar != null) {
                            LOGGER.warning("A main class is defined in multiple jar files inside " + MAIN_PREFIX + mainJar + " and " + $entry);
                            LOGGER.warning("The main class " + mainClass + " from " + mainJar + " will be used");
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.