Package java.util.jar

Examples of java.util.jar.JarOutputStream


            in = new GZIPInputStream(in);
        }

        Unpacker unpacker = Pack200.newUnpacker();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JarOutputStream jar = new JarOutputStream(baos);
        unpacker.unpack(in, jar);
        jar.close();
        return new ByteArrayInputStream(baos.toByteArray());
    }
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

       
        File  provZip = File.createTempFile("Prov-jmx-itests", ".zip");
        Manifest man = new Manifest();
        man.getMainAttributes().putValue("Manifest-Version", "1.0");
        man.getMainAttributes().putValue("Content-Type", "application/zip");
        JarOutputStream jout = new JarOutputStream(new FileOutputStream(provZip), man);
        ZipEntry entry = new ZipEntry(PROVISIONING_AGENT_CONFIG);
        jout.putNextEntry( entry );
        jout.write(new byte[] { 10, 20, 30 });
        jout.closeEntry();
        jout.flush();
        jout.close();
       
        provZip.deleteOnExit();
       
        mbean.addInformationFromZip(provZip.toURL().toExternalForm());
       
View Full Code Here

               
        File file = File.createTempFile("bundletest", ".jar");
        file.deleteOnExit();       
        Manifest man = new Manifest();
        man.getMainAttributes().putValue("Manifest-Version", "1.0");
        JarOutputStream jaros = new JarOutputStream(new FileOutputStream(file), man);
        jaros.flush();
        jaros.close();
       
        long bundleId = 0;
        try {
            bundleId = framework.installBundleFromURL(file.getAbsolutePath(), file.toURI().toString());
        } catch (Exception e) {
View Full Code Here

       
        File  provZip = File.createTempFile("Prov-jmx-itests", ".zip");
        Manifest man = new Manifest();
        man.getMainAttributes().putValue("Manifest-Version", "1.0");
        man.getMainAttributes().putValue("Content-Type", "application/zip");
        JarOutputStream jout = new JarOutputStream(new FileOutputStream(provZip), man);
        ZipEntry entry = new ZipEntry(PROVISIONING_AGENT_CONFIG);
        jout.putNextEntry( entry );
        jout.write(new byte[] { 10, 20, 30 });
        jout.closeEntry();
        jout.flush();
        jout.close();
       
        provZip.deleteOnExit();
       
        mbean.addInformationFromZip(provZip.toURL().toExternalForm());
       
View Full Code Here

   
    URL root = getClass().getClassLoader().getResource("file21");
   
    File f = new File(new File(root.toURI()), "jarfile.jar");
   
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(f));
   
    jos.putNextEntry(new ZipEntry("jar.xml"));
   
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(jos));
    writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    writer.newLine();
    writer.write("<persistence xmlns=\"http://java.sun.com/xml/ns/persistence\"");
View Full Code Here

  private static boolean createJarArchive(File archiveFile, File[] tobeJared) {
    try {
      byte buffer[] = new byte[4096];
      // Open archive file
      FileOutputStream stream = new FileOutputStream(archiveFile);
      JarOutputStream out = new JarOutputStream(stream, new Manifest());

      for (int i = 0; i < tobeJared.length; i++) {
        if (tobeJared[i] == null || !tobeJared[i].exists()
            || tobeJared[i].isDirectory()) {
          continue;
        }

        // Add archive entry
        JarEntry jarAdd = new JarEntry(tobeJared[i].getName());
        jarAdd.setTime(tobeJared[i].lastModified());
        out.putNextEntry(jarAdd);

        // Write file to archive
        FileInputStream in = new FileInputStream(tobeJared[i]);
        while (true) {
          int nRead = in.read(buffer, 0, buffer.length);
          if (nRead <= 0)
            break;
          out.write(buffer, 0, nRead);
        }
        in.close();
      }
      out.close();
      stream.close();
      LOG.info("Adding classes to jar file completed");
      return true;
    } catch (Exception ex) {
      LOG.error("Error: " + ex.getMessage());
View Full Code Here

        files.put(path, content);
    }

    public Bundle install(BundleContext ctx) throws IOException, BundleException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JarOutputStream jos = null;

        try {
            jos = new JarOutputStream(baos, makeManifest());
            addFileContent(jos);
        } finally {
            if (jos != null)
                jos.close();
            baos.close();
        }

        byte[] inMemoryJar = baos.toByteArray();
        ByteArrayInputStream bais = new ByteArrayInputStream(inMemoryJar);
View Full Code Here

  /**
   * Jar up all the contents of rootDir (recursively) into targetFile and add the manifest
   */
  public static void jarUp(File rootDir, File targetFile, Manifest manifest) throws IOException
  {
    JarOutputStream out = null;
    try {
      out = new JarOutputStream(new FileOutputStream(targetFile), manifest);
      zipUpRecursive(out, "", rootDir, new HashSet<String>(Arrays.asList("META-INF/MANIFEST.MF")));
    }
    finally {
      close(out);
    }
View Full Code Here

        files.put(path, content);
    }

    public Bundle install(BundleContext ctx) throws IOException, BundleException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JarOutputStream jos = null;

        try {
            jos = new JarOutputStream(baos, makeManifest());
            addFileContent(jos);
        } finally {
            if (jos != null)
                jos.close();
            baos.close();
        }

        byte[] inMemoryJar = baos.toByteArray();
        ByteArrayInputStream bais = new ByteArrayInputStream(inMemoryJar);
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.