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: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);//from  ww w . j  ava2  s .  c  om
    out.close();
}

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 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  w ww  .  ja v  a2  s  .  c o  m

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

From source file:MainClass.java

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

    String inName = args[0];//  w w w. j  a  va  2 s  . 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.dragome.callbackevictor.serverside.utils.RewritingUtils.java

public static void main(final String[] args) throws FileNotFoundException, IOException {
    ResourceTransformer transformer = new AsmClassTransformer();

    for (int i = 0; i < args.length; i += 2) {
        // System.out.println("rewriting " + args[i]);

        RewritingUtils.rewriteJar(new JarInputStream(new FileInputStream(args[i])), transformer,
                new JarOutputStream(new FileOutputStream(args[i + 1])));
    }/*from  w ww  .  ja  va  2  s .c o m*/

    // System.out.println("done");

}

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;/*  w ww  .j a va 2s.co m*/
    while ((count = in.read(buffer)) > 0) {
        jar.write(buffer, 0, count);
    }
    jar.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  w ww  .j  ava 2s. co 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:ezbake.frack.submitter.util.JarUtil.java

public static File addFilesToJar(File sourceJar, List<File> newFiles) throws IOException {
    JarOutputStream target = null;
    JarInputStream source;/*w ww .  j  ava2  s  . c  o m*/
    File outputJar = new File(sourceJar.getParentFile(), getRepackagedJarName(sourceJar.getAbsolutePath()));
    log.debug("Output file created at {}", outputJar.getAbsolutePath());
    outputJar.createNewFile();
    try {
        source = new JarInputStream(new FileInputStream(sourceJar));
        target = new JarOutputStream(new FileOutputStream(outputJar));
        ZipEntry entry = source.getNextEntry();
        while (entry != null) {
            String name = entry.getName();
            // Add ZIP entry to output stream.
            target.putNextEntry(new ZipEntry(name));
            // Transfer bytes from the ZIP file to the output file
            int len;
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((len = source.read(buffer)) > 0) {
                target.write(buffer, 0, len);
            }
            entry = source.getNextEntry();
        }
        source.close();
        for (File fileToAdd : newFiles) {
            add(fileToAdd, fileToAdd.getParentFile().getAbsolutePath(), target);
        }
    } finally {
        if (target != null) {
            log.debug("Closing output stream");
            target.close();
        }
    }
    return outputJar;
}

From source file:com.digitalreasoning.herman.JarCreater.java

public static void createJar(File outputJarFile, List<Entry> entries) throws IOException {
    if (!outputJarFile.getParentFile().exists()) {
        outputJarFile.getParentFile().mkdirs();
    }/*from  w  w  w .j  a v  a 2  s.  c o m*/
    if (!outputJarFile.exists()) {
        outputJarFile.createNewFile();
    }

    FileOutputStream fOut = new FileOutputStream(outputJarFile);
    JarOutputStream jarOut = new JarOutputStream(fOut);
    Set<String> packageSet = new HashSet<String>();
    try {
        for (Entry folderFile : entries) {
            InputStream inputStream = folderFile.resource.openStream();

            try {
                if (!packageSet.contains(folderFile.parentFolderName)) {
                    jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName));
                    jarOut.closeEntry();
                    packageSet.add(folderFile.parentFolderName);
                }

                jarOut.putNextEntry(new ZipEntry(folderFile.parentFolderName
                        + (folderFile.parentFolderName.endsWith("/") ? "" : "/") + folderFile.fileName));
                IOUtils.copy(inputStream, jarOut);
                jarOut.closeEntry();
            } finally {
                inputStream.close();
            }

        }

    } finally {
        jarOut.close();
        fOut.close();
    }
}

From source file:com.enderville.enderinstaller.util.InstallScript.java

/**
 * Repackages all the files in the tmp directory to the new minecraft.jar
 *
 * @param tmp The temp directory where mods were installed.
 * @param mcjar The location to save the new minecraft.jar.
 * @throws IOException//w w  w . jav  a2s  .  c o m
 */
public static void repackMCJar(File tmp, File mcjar) throws IOException {
    byte[] dat = new byte[4 * 1024];

    JarOutputStream jarout = new JarOutputStream(FileUtils.openOutputStream(mcjar));

    Queue<File> queue = new LinkedList<File>();
    for (File f : tmp.listFiles()) {
        queue.add(f);
    }

    while (!queue.isEmpty()) {
        File f = queue.poll();
        if (f.isDirectory()) {
            for (File child : f.listFiles()) {
                queue.add(child);
            }
        } else {
            //TODO need a better way to do this
            String name = f.getPath().substring(tmp.getPath().length() + 1);
            //TODO is this formatting really required for jars?
            name = name.replace("\\", "/");
            if (f.isDirectory() && !name.endsWith("/")) {
                name = name + "/";
            }
            JarEntry entry = new JarEntry(name);
            jarout.putNextEntry(entry);

            FileInputStream in = new FileInputStream(f);
            int len = -1;
            while ((len = in.read(dat)) > 0) {
                jarout.write(dat, 0, len);
            }
            in.close();
        }
        jarout.closeEntry();
    }
    jarout.close();

}