Package java.util.jar

Examples of java.util.jar.JarOutputStream


     * @param os The output stream to write to
     * @throw IOException Upon general I/O error
     * @throw JAXBException Upon error serializing to XML on disk
     */
    public void writeTo(OutputStream os) throws IOException, JAXBException {
        this.writeTo(new JarOutputStream(os));
    }
View Full Code Here


    public void execute() throws MojoExecutionException {

        // Show some info about the plugin.
        displayPluginInfo();

        JarOutputStream out = null;
        JarInputStream template = null;
        File onejarFile = null;
        try {
          // Create the target file
            onejarFile = new File(outputDirectory, filename);

            // Prepare the onejar manifest file content
            Manifest manifest = prepareManifest();
           
            // Open a stream to write to the target file
      out = new JarOutputStream(new FileOutputStream(onejarFile, false), manifest);
         
      // Add files (based on options)
            addFilesToArchive(out);
           
            // Finalize the onejar archive
View Full Code Here

            if (clazz != null) {
                addContainingJar(jarList, clazz, null, pigContext);
            }
        }
        HashMap<String, String> contents = new HashMap<String, String>();
        JarOutputStream jarFile = new JarOutputStream(os);
        Iterator<JarListEntry> it = jarList.iterator();
        while (it.hasNext()) {
            JarListEntry jarEntry = it.next();
            // log.error("Adding " + jarEntry.jar + ":" + jarEntry.prefix);
            mergeJar(jarFile, jarEntry.jar, jarEntry.prefix, contents);
        }
        for (int i = 0; i < pigContext.extraJars.size(); i++) {
            // log.error("Adding extra " + pigContext.extraJars.get(i));
            mergeJar(jarFile, pigContext.extraJars.get(i), null, contents);
        }

        jarFile.putNextEntry(new ZipEntry("pigContext"));
        new ObjectOutputStream(jarFile).writeObject(pigContext);
        jarFile.close();
    }
View Full Code Here

    public static void addFileToJar(String jarFile, String file) throws OpenEJBException {
        try {
            JarInputStream jis = new JarInputStream(new FileInputStream(jarFile));
            File tempJar = File.createTempFile("temp", "jar");
            JarOutputStream jos = new JarOutputStream(new FileOutputStream(tempJar));
            JarEntry nextJarEntry = null;
            while ((nextJarEntry = jis.getNextJarEntry()) != null) {
                jos.putNextEntry(nextJarEntry);
            }
            jis.close();
            jos.putNextEntry(new JarEntry(file));
            FileInputStream fis = new FileInputStream(file);
            for (int c = fis.read(); c != -1; c = fis.read()) {
                jos.write(c);
            }
            fis.close();
            jos.close();

            File oldJar = new File(jarFile);
            oldJar.delete();
            tempJar.renameTo(oldJar);
        } catch (FileNotFoundException e) {
View Full Code Here

            if (clazz != null) {
                addContainingJar(jarList, clazz, null, pigContext);
            }
        }
        HashMap<String, String> contents = new HashMap<String, String>();
        JarOutputStream jarFile = new JarOutputStream(os);
        Iterator<JarListEntry> it = jarList.iterator();
        while (it.hasNext()) {
            JarListEntry jarEntry = it.next();
            // log.error("Adding " + jarEntry.jar + ":" + jarEntry.prefix);
            mergeJar(jarFile, jarEntry.jar, jarEntry.prefix, contents);
        }
        for (String scriptJar: pigContext.scriptJars) {
            mergeJar(jarFile, scriptJar, null, contents);
        }
        for (URL extraJar: pigContext.extraJars) {
            // log.error("Adding extra " + pigContext.extraJars.get(i));
            mergeJar(jarFile, extraJar, null, contents);
        }
        for (int i = 0; i < pigContext.scriptFiles.size(); i++) {
          String path = pigContext.scriptFiles.get(i);
          addStream(jarFile, path, new FileInputStream(new File(path)),contents);
        }
       
        jarFile.putNextEntry(new ZipEntry("pigContext"));
        new ObjectOutputStream(jarFile).writeObject(pigContext);
        jarFile.close();
    }
View Full Code Here

        ByteArrayInputStream manifestStream = new ByteArrayInputStream(
                manifestBuf.toString().getBytes());
        Manifest manifest = new Manifest();
        manifest.read(manifestStream);

        JarOutputStream jarOut = new JarOutputStream(out, manifest);

        for (int i = 0; i < dummyClasses.size(); i++) {

            String className = dummyClasses.get(i);
           
            Class clazz = interfaceClass.getClassLoader().loadClass(className);
            className = clazz.getName().replaceAll("\\.", "/") + ".class";
            ZipEntry ze = new ZipEntry(className);
            jarOut.putNextEntry(ze);
            InputStream stream = clazz.getResourceAsStream(clazz.getSimpleName() + ".class");
           
            byte[] bytes = new byte[stream.available()];
            stream.read(bytes);
            jarOut.write(bytes);
            stream.close();
        }
       
       
        jarOut.close();
        out.close();
       
        if (existingBundle != null) {
            existingBundle.stop();
            existingBundle.uninstall();
View Full Code Here

        dummyClasses.add(interfaceClass);
        for (Class<?> clazz :  interfaceClass.getClasses()) {
            dummyClasses.add(clazz);
        }
       
        JarOutputStream jarOut = new JarOutputStream(out, manifest);

        for (int i = 0; i < dummyClasses.size(); i++) {
           
            Class<?> clazz = dummyClasses.get(i);
            String className = clazz.getName();
            className = clazz.getName().replaceAll("\\.", "/") + ".class";
            ZipEntry ze = new ZipEntry(className);
            jarOut.putNextEntry(ze);
            InputStream stream = clazz.getResourceAsStream(clazz.getSimpleName() + ".class");
           
            byte[] bytes = new byte[stream.available()];
            stream.read(bytes);
            jarOut.write(bytes);
            stream.close();
        }
       
        jarOut.close();
        out.close();
       
       
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
       
View Full Code Here

        // ensure parent directories have been created
        File parent = destinationFile.getParentFile();
        if (parent != null && !parent.exists()) parent.mkdirs();
       
        FileOutputStream fos = null;
        JarOutputStream out = null;
        try {
            byte[] buffer = new byte[4096];

            fos = new FileOutputStream(destinationFile, false);
           
            if (manifest != null) {
                out = new JarOutputStream(fos, manifest);

                // add the startup file which allows us to locate the startup directory
                out.putNextEntry(new ZipEntry(META_INF_STARTUP_JAR));
                // intentionally empty ZipEntry
                out.closeEntry();
            } else {
                out = new JarOutputStream(fos);
            }

            // write the configurationData
            ExecutableConfigurationUtil.writeConfiguration(configurationData, out);

            URI baseURI = configurationDir.getAbsoluteFile().toURI();
            Collection files = listRecursiveFiles(configurationDir);
            for (Iterator iterator = files.iterator(); iterator.hasNext();) {
                File file = (File) iterator.next();
                String relativePath = baseURI.relativize(file.toURI()).getPath();
                if (!EXCLUDED.contains(relativePath)) {
                    InputStream in = new FileInputStream(file);
                    try {
                        out.putNextEntry(new ZipEntry(relativePath));
                        try {
                            int count;
                            while ((count = in.read(buffer)) > 0) {
                                out.write(buffer, 0, count);
                            }
                        } finally {
                            out.closeEntry();
                        }
                    } finally {
                        close(in);
                    }
                }
View Full Code Here

        resourceAttributes.putValue("drink", "margarita");
        manifest.getEntries().put("resource", resourceAttributes);

        File targetDir = new File(BASEDIR, "target");
        jarFile = new File(targetDir, "resourceFinderTest.jar");
        JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        jarOutputStream.putNextEntry(new ZipEntry("resource"));
        jarOutputStream.write("resource3".getBytes());
        jarOutputStream.putNextEntry(new ZipEntry("jar3"));
        jarOutputStream.write("jar3".getBytes());
        IoUtil.close(jarOutputStream);

        alternateJarFile = new File(targetDir, "alternate.jar");
        log.debug(alternateJarFile.getAbsolutePath());
        jarOutputStream = new JarOutputStream(new FileOutputStream(alternateJarFile), manifest);
        jarOutputStream.putNextEntry(new ZipEntry("resource"));
        jarOutputStream.write("resource4".getBytes());
        jarOutputStream.putNextEntry(new ZipEntry("jar4"));
        jarOutputStream.write("jar4".getBytes());
        IoUtil.close(jarOutputStream);

        testResource = new File(targetDir, "testResource");
        FileOutputStream fileOutputStream = new FileOutputStream(testResource);
        fileOutputStream.write("testResource".getBytes());
View Full Code Here

    private static File createJarFile(int i) throws IOException {
        File file = File.createTempFile("test-" + i + "-", ".jar");
        file.deleteOnExit();
       
        FileOutputStream out = new FileOutputStream(file);
        JarOutputStream jarOut = new JarOutputStream(out);

        // common class shared by everyone
        jarOut.putNextEntry(new JarEntry(CLASS_NAME + ".class"));
        jarOut.write(createClass(CLASS_NAME));

        // class only available in this jar
        jarOut.putNextEntry(new JarEntry(CLASS_NAME + i + ".class"));
        jarOut.write(createClass(CLASS_NAME + i));

        // common resource shared by everyone
        jarOut.putNextEntry(new JarEntry(ENTRY_NAME));
        jarOut.write((ENTRY_VALUE + i).getBytes());

        // resource only available in this jar
        jarOut.putNextEntry(new JarEntry(ENTRY_NAME + i));
        jarOut.write((ENTRY_VALUE + i + ENTRY_VALUE).getBytes());

        jarOut.close();
        out.close();

        assertFileExists(file);
        return file;
    }
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.