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:Main.java

public static void main(String[] args) throws Exception {
    String inName = "a.pack.gz";
    String outName = "a.unpacked";
    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream(outName));
    InputStream in = new FileInputStream(inName);
    in = new GZIPInputStream(in);
    unpacker.unpack(in, out);//w  w w  .  j  a  v a  2s.  c om
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream("outName"));
    InputStream in = new FileInputStream("inName");
    // in = new GZIPInputStream(in);
    unpacker.unpack(in, out);// w  ww.  j a v a 2  s .c o m
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String inName = "abc.pack.gz";
    String outName = "abc";

    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream(outName));
    InputStream in = new FileInputStream(inName);
    if (inName.endsWith(".gz")) {
        in = new GZIPInputStream(in);
    }//from ww w.  j  a v  a  2  s.c om

    unpacker.unpack(in, out);
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {

    String inName = args[0];/*from   w  w w.java  2s.  co m*/
    String outName;
    if (inName.endsWith(".pack.gz")) {
        outName = inName.substring(0, inName.length() - 8);
    } else if (inName.endsWith(".pack")) {
        outName = inName.substring(0, inName.length() - 5);
    } else {
        outName = inName + ".unpacked";
    }

    JarOutputStream out = null;
    InputStream in = null;

    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    out = new JarOutputStream(new FileOutputStream(outName));
    in = new FileInputStream(inName);
    if (inName.endsWith(".gz"))
        in = new GZIPInputStream(in);
    unpacker.unpack(in, out);
    out.close();
}

From source file:com.textocat.textokit.postagger.opennlp.PackageModelZipAsArtifact.java

public static void main(String[] args) throws IOException {
    PackageModelZipAsArtifact cli = new PackageModelZipAsArtifact();
    new JCommander(cli, args);
    Path inputZipPath = Paths.get(cli.inputZipPathStr);
    if (!Files.isRegularFile(inputZipPath)) {
        System.err.println(inputZipPath + " is not an existing file.");
        System.exit(1);/*from  ww  w  .  j  ava 2s .  c o m*/
    }
    POSModelJarManifestBean manifestBean = new POSModelJarManifestBean(cli.languageCode, cli.modelVariant);
    Path outputJarPath = inputZipPath
            .resolveSibling(FilenameUtils.getBaseName(inputZipPath.getFileName().toString()) + ".jar");
    try (OutputStream out = new BufferedOutputStream(Files.newOutputStream(outputJarPath))) {
        JarOutputStream jout = new JarOutputStream(out, manifestBean.toManifest());
        jout.putNextEntry(new ZipEntry(ClasspathPOSModelHolder.getClassPath(manifestBean.getLanguageCode(),
                manifestBean.getModelVariant())));
        FileUtils.copyFile(inputZipPath.toFile(), jout);
        jout.closeEntry();
        jout.close();
    }
}

From source file:oz.hadoop.yarn.api.utils.JarUtils.java

/**
 * Will create a JAR file frombase dir/*from  ww w  .jav a2 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");
    }
    StringAssertUtils.assertNotEmptyAndNoSpacesAndEndsWith(jarName, ".jar");
    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.apache.blur.spark.util.JavaSparkUtil.java

private static String createJar(String s) throws IOException {
    File sourceFile = new File(s);
    if (sourceFile.isDirectory()) {
        File file = File.createTempFile(TMP_SPARK_JOB, JAR);
        OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
        JarOutputStream jarOut = new JarOutputStream(outputStream);
        for (File f : sourceFile.listFiles()) {
            pack(sourceFile, f, jarOut);
        }/*from w  w  w.java2  s .c o m*/
        jarOut.close();
        file.deleteOnExit();
        return file.getAbsolutePath();
    }
    throw new RuntimeException("File [" + s + "] is not a directory.");
}

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

/**
 * /*from w  w  w.j  a  va  2 s  .  co  m*/
 * @param source
 * @return
 */
public static byte[] toJarBytes(File source) {
    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");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        JarOutputStream target = new JarOutputStream(bos, manifest);
        add(source, source.getAbsolutePath().length(), target);
        target.close();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to generate JAR bytes from " + source.getAbsolutePath(), e);
    }
    return bos.toByteArray();
}

From source file:yrun.YarnRunnerUtil.java

private static Path constructJar(File sourceFile) throws IOException {
    if (sourceFile.isDirectory()) {
        File file = File.createTempFile(TMP_YARNRUNNER_JOB, JAR);
        OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
        JarOutputStream jarOut = new JarOutputStream(outputStream);
        for (File f : sourceFile.listFiles()) {
            pack(sourceFile, f, jarOut);
        }/*from w w  w  .  j a  va 2s.  co m*/
        jarOut.close();
        file.deleteOnExit();
        return new Path(file.toURI());
    }
    throw new RuntimeException("File [" + sourceFile + "] is not a directory.");
}

From source file:org.talend.designer.maven.utils.ClasspathsJarGenerator.java

public static String createJar(Property property, String classpath, String separator) throws Exception {
    String newClasspath = generateClasspathForManifest(classpath, separator);

    Manifest manifest = new Manifest();
    Attributes a = manifest.getMainAttributes();
    a.put(Attributes.Name.MANIFEST_VERSION, "1.0"); //$NON-NLS-1$
    a.put(Attributes.Name.IMPLEMENTATION_VENDOR, "Talend Open Studio"); //$NON-NLS-1$
    a.put(Attributes.Name.CLASS_PATH, newClasspath);

    String jarLocation = getJarLocation(property);
    File jarFile = new File(jarLocation);
    if (!jarFile.exists()) {
        jarFile.createNewFile();/*w  ww. ja  v a  2 s .c  om*/
    }
    JarOutputStream stream = null;
    try {
        stream = new JarOutputStream(new FileOutputStream(jarLocation), manifest);
        stream.flush();
    } finally {
        stream.close();
    }

    return getFinalClasspath(classpath, separator, jarLocation);
}