Search in sources :

Example 1 with Unpacker

use of java.util.jar.Pack200.Unpacker 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 2 with Unpacker

use of java.util.jar.Pack200.Unpacker 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 3 with Unpacker

use of java.util.jar.Pack200.Unpacker 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)

Example 4 with Unpacker

use of java.util.jar.Pack200.Unpacker 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)
            Util.closeEL(is);
        if (closeOS)
            Util.closeEL(jos);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) JarOutputStream(java.util.jar.JarOutputStream) Unpacker(java.util.jar.Pack200.Unpacker)

Example 5 with Unpacker

use of java.util.jar.Pack200.Unpacker in project Spark by igniterealtime.

the class Startup method unpackArchives.

/**
 * Converts any pack files in a directory into standard JAR files. Each
 * pack file will be deleted after being converted to a JAR. If no
 * pack files are found, this method does nothing.
 *
 * @param libDir      the directory containing pack files.
 * @param printStatus true if status ellipses should be printed when unpacking.
 */
private void unpackArchives(File libDir, boolean printStatus) {
    // Get a list of all packed files in the lib directory.
    File[] packedFiles = libDir.listFiles((dir, name) -> {
        return name.endsWith(".pack");
    });
    if (packedFiles == null) {
        // Do nothing since no .pack files were found
        return;
    }
    // Unpack each.
    boolean unpacked = false;
    for (File packedFile : packedFiles) {
        try {
            String jarName = packedFile.getName().substring(0, packedFile.getName().length() - ".pack".length());
            // Delete JAR file with same name if it exists (could be due to upgrade
            // from old Wildfire release).
            File jarFile = new File(libDir, jarName);
            if (jarFile.exists()) {
                jarFile.delete();
            }
            InputStream in = new BufferedInputStream(new FileInputStream(packedFile));
            JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(new File(libDir, jarName))));
            Pack200.Unpacker unpacker = Pack200.newUnpacker();
            // Print something so the user knows something is happening.
            if (printStatus) {
                System.out.print(".");
            }
            // Call the unpacker
            unpacker.unpack(in, out);
            in.close();
            out.close();
            packedFile.delete();
            unpacked = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // Print newline if unpacking happened.
    if (unpacked && printStatus) {
        System.out.println();
    }
}
Also used : Pack200(java.util.jar.Pack200) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

JarOutputStream (java.util.jar.JarOutputStream)13 Pack200 (java.util.jar.Pack200)9 File (java.io.File)8 FileOutputStream (java.io.FileOutputStream)8 GZIPInputStream (java.util.zip.GZIPInputStream)7 FileInputStream (java.io.FileInputStream)6 InputStream (java.io.InputStream)6 JarFile (java.util.jar.JarFile)6 BufferedInputStream (java.io.BufferedInputStream)5 Unpacker (java.util.jar.Pack200.Unpacker)5 BufferedOutputStream (java.io.BufferedOutputStream)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 OutputStream (java.io.OutputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 ListIterator (java.util.ListIterator)2 Map (java.util.Map)2