Example usage for java.util.jar JarOutputStream close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the ZIP output stream as well as the stream being filtered.

Usage

From source file:com.isomorphic.maven.util.ArchiveUtils.java

/**
 * Builds a JAR file from the contents of a directory on the filesystem (recursively).
 * Adapted from stackoverflow solution.  
 * //from  w w  w. j av  a  2  s  .  c  o m
 * @see http://stackoverflow.com/questions/1281229/how-to-use-jaroutputstream-to-create-a-jar-file
 * 
 * @param directory the directory containing the content to be xzipped up
 * @param output the zip file to be written to
 */
public static void jar(File directory, File output) throws IOException {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    output.getParentFile().mkdirs();
    JarOutputStream target = new JarOutputStream(new FileOutputStream(output), manifest);
    zip(directory, directory, target);
    target.close();
}

From source file:io.dstream.tez.utils.ClassPathUtils.java

/**
 * Will create a JAR file from base dir//from w ww. ja  v  a 2s .  c  o  m
 *
 * @param sourceDir
 * @param jarName
 * @return
 */
public static File toJar(File sourceDir, String jarName) {
    if (!sourceDir.isAbsolute()) {
        throw new IllegalArgumentException("Source must be expressed through absolute path");
    }
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    File jarFile = new File(jarName);
    try {
        JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        add(sourceDir, sourceDir.getAbsolutePath().length(), target);
        target.close();
    } catch (Exception e) {
        throw new IllegalStateException(
                "Failed to create JAR file '" + jarName + "' from " + sourceDir.getAbsolutePath(), e);
    }
    return jarFile;
}

From source file:oz.tez.deployment.utils.ClassPathUtils.java

/**
 * Will create a JAR file frombase dir//w  ww  . j  a va 2 s  . c  o m
 *
 * @param source
 * @param jarName
 * @return
 */
public static File toJar(File source, String jarName) {
    if (!source.isAbsolute()) {
        throw new IllegalArgumentException("Source must be expressed through absolute path");
    }
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    File jarFile = new File(jarName);
    try {
        JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        add(source, source.getAbsolutePath().length(), target);
        target.close();
    } catch (Exception e) {
        throw new IllegalStateException(
                "Failed to create JAR file '" + jarName + "' from " + source.getAbsolutePath(), e);
    }
    return jarFile;
}

From source file:org.exnebula.bootstrap.TestHelper.java

public static void makeMiniJar(File targetJar, File baseDirectory, String classFile) throws IOException {
    JarOutputStream jar = new JarOutputStream(new FileOutputStream(targetJar));
    jar.putNextEntry(new ZipEntry(classFile));
    byte[] buffer = new byte[4 * 1024];
    InputStream in = new FileInputStream(new File(baseDirectory, classFile));
    int count;//  ww w .  j a va  2s.  c o m
    while ((count = in.read(buffer)) > 0) {
        jar.write(buffer, 0, count);
    }
    jar.close();
}

From source file:JarMaker.java

public static void RealPackUtilityJar(String s_src, String s_dest) throws IOException {

    URL _src, _dest;//from w ww .java2 s. c  o  m

    File f_src = new File(s_src);
    if (!f_src.isDirectory())
        throw new IOException(s_src + " is not a directory");
    _src = f_src.toURL();
    _dest = new File(s_dest).toURL();

    int path_l = s_dest.lastIndexOf("/");
    if (path_l > 0) {
        File dir = new File(s_dest.substring(0, path_l));
        if (!dir.exists())
            dir.mkdirs();
    }

    JarOutputStream jout = new JarOutputStream(new FileOutputStream(_dest.getFile()));
    // put all into the jar...
    add(jout, new File(_src.getFile()), "");
    jout.close();
}

From source file:gov.nih.nci.restgen.util.GeneratorUtil.java

public static void createJar(String jarName, String folderName, String outputPath) throws IOException {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    JarOutputStream target = new JarOutputStream(new FileOutputStream(outputPath + File.separator + jarName),
            manifest);/*w ww  .j  av a  2 s  .  com*/
    add(new File(folderName), target);
    target.close();
}

From source file:com.samczsun.helios.utils.Utils.java

public static void save(File dest, Map<String, byte[]> data, Predicate<String> accept) {
    try {//from   ww  w  .  j  a v a2  s.c  o m
        JarOutputStream out = new JarOutputStream(new FileOutputStream(dest));
        Set<String> added = new HashSet<>();
        for (Entry<String, byte[]> entry : data.entrySet()) {
            String name = entry.getKey();
            if (added.add(name) && accept.test(name)) {
                out.putNextEntry(new ZipEntry(name));
                out.write(entry.getValue());
                out.closeEntry();
            }
        }
        out.close();
    } catch (IOException e) {
        ExceptionHandler.handle(e);
    }
}

From source file:org.cloudata.core.parallel.hadoop.CloudataMapReduceUtil.java

private static Path makeJarToHDFS(FileSystem fs, Path parentPath, File file) throws IOException {
    Path path = new Path(parentPath, file.getName() + ".jar");

    JarOutputStream out = new JarOutputStream(fs.create(path));
    out.putNextEntry(new JarEntry(file.getName()));

    BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

    byte[] buf = new byte[1024];

    try {/*from  ww  w.j a  va 2s .  c o  m*/
        int readBytes = 0;
        while ((readBytes = in.read(buf)) > 0) {
            out.write(buf, 0, readBytes);
        }
    } finally {
        if (out != null) {
            out.close();
        }

        if (in != null) {
            in.close();
        }
    }

    return path;
}

From source file:com.germinus.easyconf.FileUtil.java

public static void writeAsJAR(File dest, String propsFileName, Properties props)
        throws FileNotFoundException, IOException {
    JarOutputStream out = new JarOutputStream(new FileOutputStream(dest));
    JarEntry propertiesFile = new JarEntry(propsFileName);
    propertiesFile.setExtra(propertiesToString(props).getBytes());
    out.putNextEntry(propertiesFile);/*w w w. j av a 2  s  . c o m*/
    out.close();
}

From source file:org.eclipse.wb.tests.designer.TestUtils.java

/**
 * @return the path to the temporary "jar" file with single entry.
 * /*from  w w w .  j a  v  a2  s . com*/
 * @param entryName
 *          the name of entry, for example <code>"myFolder/subFolder/file.txt"</code>.
 * @param content
 *          the {@link String} content of entry.
 */
public static String createTemporaryJar(String entryName, String content) throws Exception {
    File tempFile = File.createTempFile("wbpTests", ".jar");
    tempFile.deleteOnExit();
    // create "jar" with single entry
    {
        JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(tempFile));
        jarOutputStream.putNextEntry(new ZipEntry(entryName));
        jarOutputStream.write(content.getBytes());
        jarOutputStream.closeEntry();
        jarOutputStream.close();
    }
    // return path to "jar"
    return tempFile.getAbsolutePath();
}