Example usage for java.util.jar JarOutputStream JarOutputStream

List of usage examples for java.util.jar JarOutputStream JarOutputStream

Introduction

In this page you can find the example usage for java.util.jar JarOutputStream JarOutputStream.

Prototype

public JarOutputStream(OutputStream out) throws IOException 

Source Link

Document

Creates a new JarOutputStream with no manifest.

Usage

From source file:io.fabric8.maven.proxy.impl.MavenProxyServletSupportTest.java

@Test
public void testJarUploadNoMvnPath() throws Exception {
    String jarPath = "acme-core-1.0.jar";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jas = new JarOutputStream(baos);
    addEntry(jas, "hello.txt", "Hello!".getBytes());
    jas.close();//  w w  w  .  j  a v  a  2s.  c  om

    byte[] contents = baos.toByteArray();
    testUpload(jarPath, contents, true);
}

From source file:io.fabric8.maven.proxy.impl.MavenProxyServletSupportTest.java

@Test
public void testWarUploadFullMvnPath() throws Exception {
    String warPath = "org.acme/acme-ui/1.0/acme-ui-1.0.war";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jas = new JarOutputStream(baos);
    addEntry(jas, "WEB-INF/web.xml", "<web/>".getBytes());
    jas.close();/*  w  w w  .j  a v  a 2 s  .  com*/

    byte[] contents = baos.toByteArray();

    testUpload(warPath, contents, false);
}

From source file:io.fabric8.maven.proxy.impl.MavenProxyServletSupportTest.java

@Test
public void testWarUploadWithMvnPom() throws Exception {
    String warPath = "org.acme/acme-ui/1.0/acme-ui-1.0.war";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jas = new JarOutputStream(baos);
    addEntry(jas, "WEB-INF/web.xml", "<web/>".getBytes());
    addPom(jas, "org.acme", "acme-ui", "1.0");
    jas.close();//from ww w.  j  a v a 2s .c  om

    byte[] contents = baos.toByteArray();

    testUpload(warPath, contents, false);
}

From source file:io.fabric8.maven.proxy.impl.MavenProxyServletSupportTest.java

@Test
public void testWarUploadNoMvnPath() throws Exception {
    String warPath = "acme-ui-1.0.war";

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jas = new JarOutputStream(baos);
    addEntry(jas, "WEB-INF/web.xml", "<web/>".getBytes());
    jas.close();/*from  w  ww  . j  a va 2s  .co  m*/

    byte[] contents = baos.toByteArray();

    testUpload(warPath, contents, true);
}

From source file:com.paniclauncher.workers.InstanceInstaller.java

public void deleteMetaInf() {
    File inputFile = getMinecraftJar();
    File outputTmpFile = new File(App.settings.getTempDir(), pack.getSafeName() + "-minecraft.jar");
    try {//  w w w .  j a v  a 2s. com
        JarInputStream input = new JarInputStream(new FileInputStream(inputFile));
        JarOutputStream output = new JarOutputStream(new FileOutputStream(outputTmpFile));
        JarEntry entry;

        while ((entry = input.getNextJarEntry()) != null) {
            if (entry.getName().contains("META-INF")) {
                continue;
            }
            output.putNextEntry(entry);
            byte buffer[] = new byte[1024];
            int amo;
            while ((amo = input.read(buffer, 0, 1024)) != -1) {
                output.write(buffer, 0, amo);
            }
            output.closeEntry();
        }

        input.close();
        output.close();

        inputFile.delete();
        outputTmpFile.renameTo(inputFile);
    } catch (IOException e) {
        App.settings.getConsole().logStackTrace(e);
    }
}

From source file:org.apache.oozie.action.hadoop.TestMapReduceActionExecutor.java

private Path makeUberJarWithLib(String testDir) throws Exception {
    Path jobJarPath = new Path(testDir, "uber.jar");
    FileOutputStream fos = new FileOutputStream(new File(jobJarPath.toUri().getPath()));
    JarOutputStream jos = new JarOutputStream(fos);
    // Have to put in real jar files or it will complain
    createAndAddJarToJar(jos, new File(new Path(testDir, "lib1.jar").toUri().getPath()));
    createAndAddJarToJar(jos, new File(new Path(testDir, "lib2.jar").toUri().getPath()));
    jos.close();/*from  w w  w . j a  va  2  s . c  o  m*/
    return jobJarPath;
}

From source file:org.apache.oozie.action.hadoop.TestMapReduceActionExecutor.java

private void createAndAddJarToJar(JarOutputStream jos, File jarFile) throws Exception {
    FileOutputStream fos2 = new FileOutputStream(jarFile);
    JarOutputStream jos2 = new JarOutputStream(fos2);
    // Have to have at least one entry or it will complain
    ZipEntry ze = new ZipEntry(jarFile.getName() + ".inside");
    jos2.putNextEntry(ze);// w  ww . j  a va 2s. co m
    jos2.closeEntry();
    jos2.close();
    ze = new ZipEntry("lib/" + jarFile.getName());
    jos.putNextEntry(ze);
    FileInputStream in = new FileInputStream(jarFile);
    byte buf[] = new byte[1024];
    int numRead;
    do {
        numRead = in.read(buf);
        if (numRead >= 0) {
            jos.write(buf, 0, numRead);
        }
    } while (numRead != -1);
    in.close();
    jos.closeEntry();
    jarFile.delete();
}

From source file:org.apache.brooklyn.rest.resources.BundleAndTypeResourcesTest.java

private static File createJar(Map<String, String> files) throws Exception {
    File f = Os.newTempFile("osgi", "jar");

    JarOutputStream zip = new JarOutputStream(new FileOutputStream(f));

    for (Map.Entry<String, String> entry : files.entrySet()) {
        JarEntry ze = new JarEntry(entry.getKey());
        zip.putNextEntry(ze);/*  w  ww.j av  a2 s  . c o  m*/
        zip.write(entry.getValue().getBytes());
    }

    zip.closeEntry();
    zip.flush();
    zip.close();

    return f;
}

From source file:ch.randelshofer.cubetwister.HTMLExporter.java

/**
 * Processes a pack200 template, by writing it both as a pack200 file and
 * a Jar file to the output stream./*from   w w  w  . j  a  v  a  2s . com*/
 *
 * @param filename The name of the template. Must end with ".jar.pack.gz".
 * @param in An input stream for reading the contents of the template.
 */
private void processPack200Template(String filename, InputStream in) throws IOException {
    p.setNote("Exporting " + filename + " ...");
    p.setProgress(p.getProgress() + 1);

    // Determine whether we can skip this file
    boolean skip = true;
    int pos1 = filename.lastIndexOf('/');
    int pos2 = filename.lastIndexOf("Player.jar.pack.gz");
    if (pos2 != -1) {
        for (CubeKind ck : playerCubeKinds) {
            if (ck.isNameOfKind(filename.substring(pos1 + 1, pos2))) {
                skip = false;
                break;
            }
        }
        if (skip)
            for (CubeKind ck : virtualCubeKinds) {
                if (ck.isNameOfKind(filename.substring(pos1 + 1, pos2))) {
                    skip = false;
                    break;
                }
            }
    }
    if (skip) {
        pos1 = filename.lastIndexOf("Virtual");
        pos2 = filename.lastIndexOf(".jar.pack.gz");
        if (pos2 != -1) {
            for (CubeKind ck : virtualCubeKinds) {
                if (ck.isNameOfKind(filename.substring(pos1 + 7, pos2))) {
                    skip = false;
                    break;
                }
            }
        }
    }
    if (skip) {
        return;
    }

    byte[] buf = new byte[1024];
    int len;

    // Write the pack200 file into the output and into a temporary buffer
    putNextEntry(filename);
    ByteArrayOutputStream tmp = new ByteArrayOutputStream();
    while (-1 != (len = in.read(buf, 0, buf.length))) {
        tmp.write(buf, 0, len);
        entryOut.write(buf, 0, len);
    }
    closeEntry();
    tmp.close();

    // Uncompress the pack200 file from the temporary buffer into the output
    putNextEntry(filename.substring(0, filename.length() - 8));
    InputStream itmp = new GZIPInputStream(new ByteArrayInputStream(tmp.toByteArray()));
    JarOutputStream jout = new JarOutputStream(entryOut);
    jout.setLevel(Deflater.BEST_COMPRESSION);
    Unpacker unpacker = Pack200.newUnpacker();
    unpacker.unpack(itmp, jout);

    jout.finish();
    closeEntry();
}

From source file:org.apache.hadoop.mapreduce.v2.TestMRJobs.java

private Path makeJar(Path p, int index) throws FileNotFoundException, IOException {
    FileOutputStream fos = new FileOutputStream(new File(p.toUri().getPath()));
    JarOutputStream jos = new JarOutputStream(fos);
    ZipEntry ze = new ZipEntry("distributed.jar.inside" + index);
    jos.putNextEntry(ze);/*from   w  w  w.  j  a va 2  s.  c  o m*/
    jos.write(("inside the jar!" + index).getBytes());
    jos.closeEntry();
    jos.close();
    localFs.setPermission(p, new FsPermission("700"));
    return p;
}