Search in sources :

Example 1 with Pack200

use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.

the class Utils method pack.

// given a jar file foo.jar will write to foo.pack
static void pack(JarFile jarFile, File packFile) throws IOException {
    Pack200.Packer packer = Pack200.newPacker();
    Map<String, String> p = packer.properties();
    // Take the time optimization vs. space
    // CAUTION: do not use 0.
    p.put(packer.EFFORT, "1");
    // Make the memory consumption as effective as possible
    p.put(packer.SEGMENT_LIMIT, "10000");
    // ignore all JAR deflation requests to save time
    p.put(packer.DEFLATE_HINT, packer.FALSE);
    // save the file ordering of the original JAR
    p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
    FileOutputStream fos = null;
    try {
        // Write out to a jtreg scratch area
        fos = new FileOutputStream(packFile);
        // Call the packer
        packer.pack(jarFile, fos);
    } finally {
        close(fos);
    }
}
Also used : Pack200(java.util.jar.Pack200) FileOutputStream(java.io.FileOutputStream)

Example 2 with Pack200

use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.

the class T7007157 method main.

public static void main(String... args) throws IOException {
    File sdkHome = Utils.JavaSDK;
    File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
    JarFile jarFile = new JarFile(testJar);
    File packFile = new File("foo.pack");
    Pack200.Packer packer = Pack200.newPacker();
    Map<String, String> p = packer.properties();
    // Take the time optimization vs. space
    // CAUTION: do not use 0.
    p.put(packer.EFFORT, "1");
    // Make the memory consumption as effective as possible
    p.put(packer.SEGMENT_LIMIT, "10000");
    // ignore all JAR deflation requests to save time
    p.put(packer.DEFLATE_HINT, packer.FALSE);
    // save the file ordering of the original JAR
    p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
    // strip the StackMapTables
    p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
    FileOutputStream fos = null;
    try {
        // Write out to a jtreg scratch area
        fos = new FileOutputStream(packFile);
        // Call the packer
        packer.pack(jarFile, fos);
    } finally {
        Utils.close(fos);
        Utils.close(jarFile);
    }
    Utils.cleanup();
}
Also used : Pack200(java.util.jar.Pack200) FileOutputStream(java.io.FileOutputStream) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 3 with Pack200

use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.

the class TestExceptions method unpack200Test2.

// test the Pack200.unpack(File, OutputStream);
static void unpack200Test2() {
    List<UnpackTestFileInput> tlist = new ArrayList<UnpackTestFileInput>();
    try {
        // setup the test scenarios
        try {
            tlist.add(new UnpackTestFileInput((File) null, null));
            tlist.add(new UnpackTestFileInput(testPackFile, null));
            tlist.add(new UnpackTestFileInput((File) null, new JarOutputStream(new ByteArrayOutputStream())));
        } catch (Exception e) {
            throw new Error("Initialization error", e);
        }
        // test the scenarios
        for (UnpackTestFileInput ti : tlist) {
            System.out.println(ti);
            try {
                Pack200.Unpacker unpacker = Pack200.newUnpacker();
                unpacker.unpack(ti.getInputFile(), ti.getJarOutputStream());
            } catch (Exception e) {
                ti.checkException(e);
            }
        }
    } finally {
        // keep jprt happy
        for (TestInput ti : tlist) {
            if (ti != null) {
                ti.close();
            }
        }
    }
}
Also used : Pack200(java.util.jar.Pack200) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarFile(java.util.jar.JarFile) File(java.io.File) IOException(java.io.IOException)

Example 4 with Pack200

use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.

the class TestExceptions method unpack200Test1.

// test the Pack200.unpack(InputStream, OutputStream);
static void unpack200Test1() {
    List<UnpackTestInput> tlist = new ArrayList<UnpackTestInput>();
    try {
        // setup the test scenarios
        try {
            tlist.add(new UnpackTestInput((InputStream) null, null));
            tlist.add(new UnpackTestInput(new FileInputStream(testPackFile), null));
            tlist.add(new UnpackTestInput((InputStream) null, new JarOutputStream(new ByteArrayOutputStream())));
        } catch (Exception e) {
            throw new Error("Initialization error", e);
        }
        // test the scenarios
        for (UnpackTestInput ti : tlist) {
            System.out.println(ti);
            try {
                Pack200.Unpacker unpacker = Pack200.newUnpacker();
                unpacker.unpack(ti.getInputStream(), ti.getJarOutputStream());
            } catch (Exception e) {
                ti.checkException(e);
            }
        }
    } finally {
        // keep jprt happy
        for (TestInput ti : tlist) {
            if (ti != null) {
                ti.close();
            }
        }
    }
}
Also used : Pack200(java.util.jar.Pack200) FileInputStream(java.io.FileInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 5 with Pack200

use of java.util.jar.Pack200 in project Lucee by lucee.

the class Pack200Util method pack2Jar.

public static void pack2Jar(InputStream is, OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
    Unpacker unpacker = Pack200.newUnpacker();
    SortedMap<String, String> p = unpacker.properties();
    p.put(Unpacker.DEFLATE_HINT, Unpacker.TRUE);
    is = new GZIPInputStream(is);
    JarOutputStream jos = null;
    try {
        jos = new JarOutputStream(os);
        unpacker.unpack(is, jos);
        jos.finish();
    } finally {
        if (closeIS)
            IOUtil.closeEL(is);
        if (closeOS)
            IOUtil.closeEL(jos);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JarOutputStream(java.util.jar.JarOutputStream) Unpacker(java.util.jar.Pack200.Unpacker)

Aggregations

Pack200 (java.util.jar.Pack200)14 JarOutputStream (java.util.jar.JarOutputStream)13 File (java.io.File)11 FileOutputStream (java.io.FileOutputStream)11 JarFile (java.util.jar.JarFile)9 FileInputStream (java.io.FileInputStream)7 IOException (java.io.IOException)7 Packer (java.util.jar.Pack200.Packer)7 GZIPInputStream (java.util.zip.GZIPInputStream)7 InputStream (java.io.InputStream)6 JarInputStream (java.util.jar.JarInputStream)6 BufferedInputStream (java.io.BufferedInputStream)5 ArrayList (java.util.ArrayList)5 Unpacker (java.util.jar.Pack200.Unpacker)5 GZIPOutputStream (java.util.zip.GZIPOutputStream)5 BufferedOutputStream (java.io.BufferedOutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4 Map (java.util.Map)4