Example usage for java.util.jar JarOutputStream write

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

Introduction

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

Prototype

public void write(int b) throws IOException 

Source Link

Document

Writes a byte to the compressed output stream.

Usage

From source file:org.apache.sysml.utils.lite.BuildLite.java

/**
 * Write an identifier file to the lite jar that can be used to identify
 * that the lite jar is being used.//from w  w  w  .j  a  v a2  s.  c  o  m
 * 
 * @param jos
 *            output stream to the jar being written
 * @param numFilesWritten
 *            the number of files written to the jar so far
 * @throws IOException
 *             if an IOException occurs
 */
private static void writeIdentifierFileToLiteJar(JarOutputStream jos, int numFilesWritten) throws IOException {
    writeMessage(LITE_JAR_IDENTIFIER_FILE, numFilesWritten);
    JarEntry je = new JarEntry(LITE_JAR_IDENTIFIER_FILE);
    jos.putNextEntry(je);
    String created = "Created " + (new Date());
    String userName = System.getProperty("user.name");
    if (userName != null) {
        created = created + " by " + userName;
    }
    jos.write(created.getBytes());
}

From source file:org.apache.sysml.utils.lite.BuildLite.java

/**
 * Write the additional resources to the jar.
 * //from   w ww.  jav a  2  s.com
 * @param jos
 *            output stream to the jar being written
 * @param numFilesWritten
 *            the number of files written to the jar so far
 * @throws IOException
 *             if an IOException occurs
 */
private static void writeAdditionalResourcesToJar(JarOutputStream jos, int numFilesWritten) throws IOException {
    for (String resource : additionalResources) {
        writeMessage(resource, ++numFilesWritten);
        JarEntry je = new JarEntry(resource);
        jos.putNextEntry(je);
        ClassLoader cl = BuildLite.class.getClassLoader();
        InputStream is = cl.getResourceAsStream(resource);
        byte[] bytes = IOUtils.toByteArray(is);
        jos.write(bytes);
    }
}

From source file:org.apache.hadoop.util.TestApplicationClassLoader.java

private File makeTestJar() throws IOException {
    File jarFile = new File(testDir, "test.jar");
    JarOutputStream out = new JarOutputStream(new FileOutputStream(jarFile));
    ZipEntry entry = new ZipEntry("resource.txt");
    out.putNextEntry(entry);/*from   w w  w .  j  a  va 2  s.c o m*/
    out.write("hello".getBytes());
    out.closeEntry();
    out.close();
    return jarFile;
}

From source file:org.apache.hadoop.filecache.TestMRWithDistributedCache.java

private Path makeJar(Path p, int index) throws FileNotFoundException, IOException {
    FileOutputStream fos = new FileOutputStream(new File(p.toString()));
    JarOutputStream jos = new JarOutputStream(fos);
    ZipEntry ze = new ZipEntry("distributed.jar.inside" + index);
    jos.putNextEntry(ze);/*  w  w w  .ja v  a2  s  .com*/
    jos.write(("inside the jar!" + index).getBytes());
    jos.closeEntry();
    jos.close();
    return p;
}

From source file:com.streamsets.datacollector.cluster.TestTarFileCreator.java

private File createJar(File parentDir) throws IOException {
    if (parentDir.isFile()) {
        parentDir.delete();//  w w w  .jav a2 s . co  m
    }
    parentDir.mkdirs();
    Assert.assertTrue(parentDir.isDirectory());
    String uuid = UUID.randomUUID().toString();
    File jar = new File(parentDir, uuid + ".jar");
    JarOutputStream out = new JarOutputStream(new FileOutputStream(jar));
    JarEntry entry = new JarEntry("sample.txt");
    out.putNextEntry(entry);
    out.write(uuid.getBytes(StandardCharsets.UTF_8));
    out.closeEntry();
    out.close();
    return jar;
}

From source file:org.apache.apex.malhar.sql.schema.TupleSchemaRegistry.java

public String generateCommonJar() throws IOException {
    File file = File.createTempFile("schemaSQL", ".jar");

    FileSystem fs = FileSystem.newInstance(file.toURI(), new Configuration());
    FSDataOutputStream out = fs.create(new Path(file.getAbsolutePath()));
    JarOutputStream jout = new JarOutputStream(out);

    for (Schema schema : schemas.values()) {
        jout.putNextEntry(new ZipEntry(schema.fqcn.replace(".", "/") + ".class"));
        jout.write(schema.beanClassBytes);
        jout.closeEntry();/*from w  w w  . j  a  va 2  s.  c  om*/
    }

    jout.close();
    out.close();

    return file.getAbsolutePath();
}

From source file:org.sakaiproject.kernel.component.core.test.ComponentLoaderServiceImplTest.java

/**
 * @param file//from   w ww.ja  va  2 s  .  co  m
 * @throws IOException
 */
private void createComponent(File f, String component) throws IOException {
    if (f.getParentFile().mkdirs()) {
        if (debug)
            LOG.debug("Created Directory " + f);
    }
    JarOutputStream jarOutput = new JarOutputStream(new FileOutputStream(f));
    JarEntry jarEntry = new JarEntry("SAKAI-INF/component.xml");
    jarOutput.putNextEntry(jarEntry);
    String componentXml = ResourceLoader.readResource(component, this.getClass().getClassLoader());
    jarOutput.write(componentXml.getBytes("UTF-8"));
    jarOutput.closeEntry();
    jarOutput.close();
}

From source file:com.h3xstream.findbugs.test.service.FindBugsLauncher.java

private void addFilesToStream(final ClassLoader cl, final JarOutputStream jar, final File dir,
        final String path) throws IOException {
    for (final File nextFile : dir.listFiles()) {
        if (nextFile.isFile()) {
            final String resource = path + nextFile.getName();
            jar.putNextEntry(new ZipEntry(resource));
            jar.write(IOUtils.toByteArray(cl.getResourceAsStream("metadata/" + resource)));
        } else {/*  www. ja  v a  2  s  . c  o m*/
            addFilesToStream(cl, jar, nextFile, path + nextFile.getName() + "/");
        }
    }
}

From source file:com.francetelecom.clara.cloud.mvn.consumer.maven.MavenDeployer.java

private File populateJarArchive(File archive, List<FileRef> fileset) throws IOException {
    archive.getParentFile().mkdirs();//  w w  w . ja va2s. c o m
    JarOutputStream target = new JarOutputStream(new FileOutputStream(archive));
    for (FileRef fileRef : fileset) {
        JarEntry jarAdd = new JarEntry(fileRef.getRelativeLocation());
        target.putNextEntry(jarAdd);
        target.write(fileRef.getContent().getBytes());
    }
    target.close();
    return archive;
}

From source file:org.apache.openjpa.eclipse.PluginLibrary.java

void copyJar(JarInputStream jar, JarOutputStream out) throws IOException {
    if (jar == null || out == null)
        return;/*from  www  .ja  v a2 s  . com*/

    try {
        JarEntry entry = null;
        while ((entry = jar.getNextJarEntry()) != null) {
            out.putNextEntry(entry);
            int b = -1;
            while ((b = jar.read()) != -1) {
                out.write(b);
            }
        }
        out.closeEntry();
    } finally {
        out.finish();
        out.flush();
        out.close();
        jar.close();
    }
}