Package java.util.jar

Examples of java.util.jar.JarInputStream


                File file = new File(rarPath);
                URL rarUrl = file.toURI().toURL();
               
                String jarPath = path.substring(index+1, path.indexOf(JAR_SEPARATOR,index+1));
                JarFile rarFile = new JarFile(file);
                mf = new JarInputStream(rarFile.getInputStream(rarFile.getEntry(jarPath))).getManifest();
                if (mf == null)
                {
                    return null;
                }
                return registerBundle(mf, rarUrl);
View Full Code Here


        LinkedList<byte[]> fileData = new LinkedList<byte[]>();
        int limit = Integer.parseInt(args[1]);
        try {
            long totalSize = 0;
            JarInputStream jar = new JarInputStream(new FileInputStream(args[0]));
            JarEntry entry = jar.getNextJarEntry();
            while (fileData.size() < limit && entry != null) {
                String name = entry.getName();
                if (name.endsWith(".class")) {
                    if (entry.getSize() != -1) {
                        int len = (int) entry.getSize();
                        byte[] data = new byte[len];
                        int l = jar.read(data);
                        assert l == len;
                        fileData.add(data);
                        totalSize += data.length;
                    } else {
                        System.err.println("No jar-entry size given... Unimplemented, jar file not supported");
                    }
                }
                entry = jar.getNextJarEntry();
            }
            System.out.println(memFormat(totalSize) + " class data, ~"
                    + memFormat(totalSize / limit) + " per class.");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
View Full Code Here

   
    // Namen f�r tempor�re Datei setzen
    String tempfile = jarFile.getCanonicalPath();
    tempfile = tempfile.substring(0,tempfile.length()-jarFile.getName().length())+randomName;
   
    JarInputStream jarIn = new JarInputStream(new FileInputStream(jarFile.getPath()));
    JarOutputStream jarOut = new JarOutputStream(new FileOutputStream( tempfile ), manifest);
   
    if ( this.compression != -1)
      jarOut.setLevel(this.compression);
   
    // We must write every entry from the input JAR to the output JAR, so iterate over the entries:
    // Create a read buffer to transfer data from the input
   
    byte[] buffer = new byte[4096];
    JarEntry entry;
    String path;
    Hashtable inventory = new Hashtable();
   
    int nrOfWrittenFiles = 0;
   
    // add the new files
    for (int i = 0; i < tobeJared.length; i++) {
     
      if ( tobeJared[i] == null )
        continue;
      if ( !tobeJared[i].exists() || tobeJared[i].isDirectory() )
        continue;
     
      // Zielpfad der Datei auf die package-Struktur reduzieren
      path = tobeJared[i].getPath().substring(this.source.length());
      path = path.replaceAll("\\\\", "/");
     
      // Datei ist im Original schon enthalten?
      if ( jarContent.get(path)!=null )
        this.log("\n overwriting " + path);
      else
        this.log("\n      adding " + path);
     
      // Add archive entry
      entry = new JarEntry(path);
      entry.setTime(tobeJared[i].lastModified());
      jarOut.putNextEntry(entry);
     
      // Klasse ins Archiv schreiben
      FileInputStream in = new FileInputStream(tobeJared[i]);
     
      while ( true ) {
       
        int nRead = in.read(buffer, 0, buffer.length);
        if ( nRead <= 0 )
          break;
       
        jarOut.write(buffer, 0, nRead);
      }
     
      inventory.put(entry.getName(), "notnull");
     
      in.close();
      nrOfWrittenFiles++;
    }
   
    // Iterate the entries of the original file
    while ((entry = jarIn.getNextJarEntry()) != null) {
     
      // Exclude the manifest file from the old JAR
      if ("META-INF/MANIFEST.MF".equals(entry.getName())) continue;
     
      // Datei befindet sich bereits im jar
      if ( inventory.get(entry.getName())!=null )
        continue;
     
      // Write the entry to the output JAR
      jarOut.putNextEntry(entry);
      int read;
      while ((read = jarIn.read(buffer)) != -1) {
        jarOut.write(buffer, 0, read);
      }
     
      jarOut.closeEntry();
    }
   
    // Flush and close all the streams
    jarOut.flush();
    jarOut.close();
    jarIn.close();
   
  // altes jar l�schen und neue Datei umbenennen
    File oldJar = new File(this.targetPath);
    try {
      if ( !jarFile.delete() )
View Full Code Here

  protected void analyzeJar(Resource res) throws BuildException {
    log("Analyze jar file " + res, Project.MSG_VERBOSE);

    try {
      final JarInputStream jarStream = new JarInputStream(res.getInputStream());

      ZipEntry ze = jarStream.getNextEntry();
      while(null!=ze) {
        final String fileName = ze.getName();
        if (fileName.endsWith(".class")) {
          log("Analyze jar class file " + fileName, Project.MSG_VERBOSE);
          asmAnalyser.analyseClass(jarStream, fileName);
        }
        ze = jarStream.getNextEntry();
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new BuildException("Failed to analyze class-file " +
                               res + ", exception=" + e, getLocation());
View Full Code Here

    throws DeploymentException
  {
    try {
      log.debug("Loading "+module.getName() +"-" +module.getVersion()
                +" from "+moduleUrl);
      JarInputStream ji = new JarInputStream(moduleUrl.openStream());
      ZipEntry ze;

      do {
        ze = ji.getNextJarEntry();
        if (ze==null) {
          ji.close();
          throw new DeploymentException("module.xml missing");
        }
      } while (!"META-INF/module.xml".equals(ze.getName()));

      ModuleBuilder moduleBuilder = new ModuleBuilder(ji, module, axisConfig);
View Full Code Here

      }


      // Copy jarunpacker files, if availbale
      if(jarunpacker_in != null) {
        JarInputStream jar_in = null;

        try {
          jar_in = new JarInputStream(new BufferedInputStream(jarunpacker_in));

          ZipEntry srcEntry;
          while(null != (srcEntry = jar_in.getNextEntry())) {

            // Skip unused files from jarunpacker
            if(srcEntry.getName().startsWith("META-INF") ||
               srcEntry.getName().startsWith("OSGI-OPT")) {
              continue;
            }

            ZipEntry destEntry = new ZipEntry(srcEntry.getName());

            out.putNextEntry(destEntry);

            long nTotal = 0;
            int n = 0;
            while (-1 != (n = jar_in.read(buf, 0, buf.length))) {
              out.write(buf, 0, n);
              nTotal += n;
            }
          }
        } finally {
          try { jar_in.close()} catch (Exception ignored) {  }
        }
      } else {
        Activator.log.warn("No jarunpacker available");
      }
      // end of jarunpacker copy
View Full Code Here

            is.close();

            if (extract)
            {
                is = new FileInputStream(file);
                JarInputStream jis = new JarInputStream(is);
                out.println("Extracting...");
                unjar(jis, dir);
                jis.close();
                file.delete();
            }
        }
        catch (Exception ex)
        {
View Full Code Here

        RuleSetCompiler[] compilers;

        // single URL parameter
        ruleSetLoader.addFromUrl( RuleSetLoaderTest.class.getResource( "simple.java.drl" ) );
        compilers = (RuleSetCompiler[]) ruleSetLoader.getRuleSets().values().toArray( new RuleSetCompiler[]{} );
        JarInputStream jis = new JarInputStream( new ByteArrayInputStream( compilers[0].getSourceDeploymentJar() ) );
        JarEntry entry = null;
        Map entries = new HashMap();
        Map classNames = new HashMap();

        ByteArrayOutputStream bos = null;

        // get all the entries from the jar
        while ( (entry = jis.getNextJarEntry()) != null )
        {
            bos = new ByteArrayOutputStream();
            copy( jis,
                  bos );
            //we have to remove the namespace datestamp, as its random
View Full Code Here

        // single URL parameter
        ruleSetLoader.addFromUrl( RuleSetLoaderTest.class.getResource( "simple.java.drl" ) );
        compilers = (RuleSetCompiler[]) ruleSetLoader.getRuleSets().values().toArray( new RuleSetCompiler[]{} );
        byte[] jarBytes = compilers[0].getBinaryDeploymentJar();
        JarInputStream jis = new JarInputStream( new ByteArrayInputStream( jarBytes ) );
        JarEntry entry = null;
        Map entries = new HashMap();
        Map classNames = new HashMap();

        ByteArrayOutputStream bos = null;

        //get all the entries from the jar
        while ( (entry = jis.getNextJarEntry()) != null )
        {
            bos = new ByteArrayOutputStream();
            copy( jis,
                  bos );
            //we have to remove the namespace datestamp, as its random
View Full Code Here

                File file = new File(rarPath);
                URL rarUrl = file.toURI().toURL();
               
                String jarPath = path.substring(index+1, path.indexOf(JAR_SEPARATOR,index+1));
                JarFile rarFile = new JarFile(file);
                JarInputStream jis = new JarInputStream(rarFile.getInputStream(rarFile.getEntry(jarPath)));
                try
                {
                    mf = jis.getManifest();
                    if (mf == null)
                    {
                        return null;
                    }
                }
                finally
                {
                    jis.close();
                }
                return registerBundle(mf, rarUrl);
            }
            else if (manifest.getProtocol().equals("vfsfile") || manifest.getProtocol().equals("vfsjar") ||
                manifest.getProtocol().equals("vfszip") || manifest.getProtocol().equals("vfs") )
            {
                // protocol formats:
                // vfsfile:<path>!<manifest-file>, vfsjar:<path>!<manifest-file>, vfszip:<path>!<manifest-file>
                String path = StringUtils.getDecodedStringFromURLString(manifest.toExternalForm());
                int index = path.indexOf(JAR_SEPARATOR);
                if (index < 0)
                {
                    NucleusLogger.PLUGIN.warn("Unable to find jar bundle for " + path + " so ignoring");
                    return null;
                }
                else
                {
                    String jarPath = path.substring(0, index);
                    URL jarUrl = new URL(jarPath);

                    JarInputStream jis = null;
                    InputStream inputStream = jarUrl.openConnection().getInputStream();
                   
                    // JBoss 6 returns a JarInputStream instead of FileInputStream as previous versions
                    // which won't return the manifest below if we use it to construct a new JarInputStream,
                    // so we just use it.
                    if ( inputStream instanceof JarInputStream )
                    {
                      jis = (JarInputStream) inputStream;
                    }
                    else
                    {
                      jis = new JarInputStream(inputStream);
                    }
                   
                    try
                    {
                        mf = jis.getManifest();
                        if (mf == null)
                        {
                            return null;
                        }
                    }
                    finally
                    {
                        jis.close();
                    }
                    return registerBundle(mf, jarUrl);
                }
            }
            else
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.