Package java.util.jar

Examples of java.util.jar.JarOutputStream


      attr.put(dateAttr, now);
      map.put(className+".class", attr);
  }

  final File jarFile = new File(_destDir, _jarFileName);
  final JarOutputStream jos =
      new JarOutputStream(new FileOutputStream(jarFile), manifest);
  classes = _bcelClasses.elements();
  while (classes.hasMoreElements()) {
      final JavaClass clazz = (JavaClass)classes.nextElement();
      final String className = clazz.getClassName().replace('.','/');
      jos.putNextEntry(new JarEntry(className+".class"));
      final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
      clazz.dump(out); // dump() closes it's output stream
      out.writeTo(jos);
  }
  jos.close();
    }
View Full Code Here


            assertTrue( data.indexOf( resourceNames[x] ) != -1 );
        }

        if ( null != jarName )
        {
            JarOutputStream jar = new JarOutputStream( new FileOutputStream( jarName ) );
            jar.putNextEntry( new ZipEntry( "META-INF/maven/remote-resources.xml" ) );
            jar.write( data.getBytes() );
            jar.closeEntry();

            for ( int x = 0; x < resourceNames.length; x++ )
            {
                File resource = new File( resourceDir, resourceNames[x] );
                InputStream in = new FileInputStream( resource );
                jar.putNextEntry( new ZipEntry( resourceNames[x] ) );
                IOUtil.copy( in, jar );
                IOUtil.close( in );
                jar.closeEntry();
            }
            jar.close();
        }
    }
View Full Code Here

    private void writeConfiguration(final ConfigurationData configurationData) throws IOException {
        if (expanded) {
            ExecutableConfigurationUtil.writeConfiguration(configurationData, carFile);
        }
        else {
            JarOutputStream out = null;
            try {
                out = new JarOutputStream(new FileOutputStream(carFile));
                ExecutableConfigurationUtil.writeConfiguration(configurationData, out);
                out.flush();
            }
            finally {
                if (out != null) {
                    try {
                        out.close();
                    }
                    catch (IOException ignored) {
                        // ignored
                    }
                }
View Full Code Here

        if (!dir.isDirectory()) { // must be a packed (JAR-formatted) plugin
            try {
                File temp = new File(dir.getParentFile(), dir.getName() + ".temp");
                JarFile input = new JarFile(dir);
                Manifest manifest = input.getManifest();
                JarOutputStream out = manifest == null ? new JarOutputStream(
                        new BufferedOutputStream(new FileOutputStream(temp)))
                        : new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)), manifest);
                Enumeration en = input.entries();
                byte[] buf = new byte[4096];
                int count;
                while (en.hasMoreElements()) {
                    JarEntry entry = (JarEntry) en.nextElement();
                    if (entry.getName().equals("META-INF/geronimo-plugin.xml")) {
                        entry = new JarEntry(entry.getName());
                        out.putNextEntry(entry);
                        PluginXmlUtil.writePluginMetadata(metadata, out);
                    } else if (entry.getName().equals("META-INF/MANIFEST.MF")) {
                        // do nothing, already passed in a manifest
                    } else {
                        out.putNextEntry(entry);
                        InputStream in = input.getInputStream(entry);
                        while ((count = in.read(buf)) > -1) {
                            out.write(buf, 0, count);
                        }
                        in.close();
                        out.closeEntry();
                    }
                }
                out.flush();
                out.close();
                input.close();
                if (!dir.delete()) {
                    log.error("Unable to delete old plugin at " + dir.getAbsolutePath());
                    throw new IOException("Unable to delete old plugin at " + dir.getAbsolutePath());
                }
View Full Code Here

        if (!dir.isDirectory()) { // must be a packed (JAR-formatted) plugin
            try {
                File temp = new File(dir.getParentFile(), dir.getName() + ".temp");
                JarFile input = new JarFile(dir);
                Manifest manifest = input.getManifest();
                JarOutputStream out = manifest == null ? new JarOutputStream(
                        new BufferedOutputStream(new FileOutputStream(temp)))
                        : new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)), manifest);
                Enumeration en = input.entries();
                byte[] buf = new byte[4096];
                int count;
                while (en.hasMoreElements()) {
                    JarEntry entry = (JarEntry) en.nextElement();
                    if (entry.getName().equals("META-INF/geronimo-plugin.xml")) {
                        entry = new JarEntry(entry.getName());
                        out.putNextEntry(entry);
                        PluginXmlUtil.writePluginMetadata(metadata, out);
                    } else if (entry.getName().equals("META-INF/MANIFEST.MF")) {
                        // do nothing, already passed in a manifest
                    } else {
                        out.putNextEntry(entry);
                        InputStream in = input.getInputStream(entry);
                        while ((count = in.read(buf)) > -1) {
                            out.write(buf, 0, count);
                        }
                        in.close();
                        out.closeEntry();
                    }
                }
                out.flush();
                out.close();
                input.close();
                if (!dir.delete()) {
                    log.error("Unable to delete old plugin at " + dir.getAbsolutePath());
                    throw new IOException("Unable to delete old plugin at " + dir.getAbsolutePath());
                }
View Full Code Here

                // out target is just a plain old jar file directly accessabel from the file system
                copyFile(new File(baseJar.getName()), outputFile);
            }
        } else {
            // copy out the module contents to a standalone jar file (entry by entry)
            JarOutputStream out = null;
            try {
                out = new JarOutputStream(new FileOutputStream(outputFile));
                byte[] buffer = new byte[4096];
                Enumeration entries = inputJar.entries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry) entries.nextElement();
                    InputStream in = inputJar.getInputStream(entry);
                    try {
                        out.putNextEntry(new ZipEntry(entry.getName()));
                        try {
                            int count;
                            while ((count = in.read(buffer)) > 0) {
                                out.write(buffer, 0, count);
                            }
                        } finally {
                            out.closeEntry();
                        }
                    } finally {
                        close(in);
                    }
                }
View Full Code Here

        if(!dir.isDirectory()) { // must be a packed (JAR-formatted) plugin
            try {
                File temp = new File(dir.getParentFile(), dir.getName()+".temp");
                JarFile input = new JarFile(dir);
                Manifest manifest = input.getManifest();
                JarOutputStream out = manifest == null ? new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)))
                        : new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)), manifest);
                Enumeration en = input.entries();
                byte[] buf = new byte[4096];
                int count;
                while (en.hasMoreElements()) {
                    JarEntry entry = (JarEntry) en.nextElement();
                    if(entry.getName().equals("META-INF/geronimo-plugin.xml")) {
                        entry = new JarEntry(entry.getName());
                        out.putNextEntry(entry);
                        Document doc = writePluginMetadata(metadata);
                        TransformerFactory xfactory = XmlUtil.newTransformerFactory();
                        Transformer xform = xfactory.newTransformer();
                        xform.setOutputProperty(OutputKeys.INDENT, "yes");
                        xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
                        xform.transform(new DOMSource(doc), new StreamResult(out));
                    } else if(entry.getName().equals("META-INF/MANIFEST.MF")) {
                        // do nothing, already passed in a manifest
                    } else {
                        out.putNextEntry(entry);
                        InputStream in = input.getInputStream(entry);
                        while((count = in.read(buf)) > -1) {
                            out.write(buf, 0, count);
                        }
                        in.close();
                        out.closeEntry();
                    }
                }
                out.flush();
                out.close();
                input.close();
                if(!dir.delete()) {
                    throw new IOException("Unable to delete old plugin at "+dir.getAbsolutePath());
                }
                if(!temp.renameTo(dir)) {
View Full Code Here

        generateLocalWSDL(context);
       
      
        File clientJarFile = new File((String)context.get(ToolConstants.CFG_OUTPUTDIR),
                                      (String)context.get(ToolConstants.CFG_CLIENT_JAR));
        JarOutputStream jarout = null;
        try {
            jarout = new JarOutputStream(new FileOutputStream(clientJarFile), new Manifest());
            createClientJar(tmpDir, jarout);
            jarout.close();
        } catch (Exception e) {
            LOG.log(Level.SEVERE, "FAILED_TO_CREAT_CLIENTJAR", e);
            Message msg = new Message("FAILED_TO_CREAT_CLIENTJAR", LOG);
            throw new ToolException(msg, e);
        }   
View Full Code Here

      Attributes att = newman.getMainAttributes();
      att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
      att.put(Attributes.Name.MAIN_CLASS, element);

      File outputJar = null;
      JarOutputStream jout = null;

      // open the output jarfile
      outputJar = File.createTempFile("hyts_", ".jar");
      jout = new JarOutputStream(new FileOutputStream(outputJar),
          newman);
      jout.putNextEntry(new JarEntry(entryName));

      File resources = Support_Resources.createTempFolder();

                        // read in the class file, and output it to the jar
      Support_Resources.copyFile(resources, null, testClass);
      URL jarURL = new URL((new File(resources, testClass)).toURL()
          .toString());
      InputStream jis = jarURL.openStream();
      byte[] bytes = new byte[1024];
      int len;
      while ((len = jis.read(bytes)) != -1) {
                            jout.write(bytes, 0, len);
                        }
      jout.flush();
      jout.close();
      jis.close();

      String res = null;
      // set up the VM parameters
      String[] args = new String[2];
View Full Code Here

        att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
        att.put(Attributes.Name.CLASS_PATH, barZip.getName());

        fos.close();
        try {
            new JarOutputStream(fos, man);
            fail("IOException expected");
        } catch (IOException ee) {
            // expected
        }
    }
View Full Code Here

TOP

Related Classes of java.util.jar.JarOutputStream

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.