Search in sources :

Example 11 with Pack200

use of java.util.jar.Pack200 in project lwjgl by LWJGL.

the class AppletLoader method extractPack.

/**
 *  Extract Pack File
 *  @param in Input path to pack file
 *  @param out output path to resulting file
 *  @throws Exception if any errors occur
 */
protected void extractPack(String in, String out) throws Exception {
    File f = new File(in);
    FileOutputStream fostream = new FileOutputStream(out);
    JarOutputStream jostream = new JarOutputStream(fostream);
    try {
        Pack200.Unpacker unpacker = Pack200.newUnpacker();
        unpacker.unpack(f, jostream);
    } finally {
        jostream.close();
        fostream.close();
    }
    // delete pack file as its no longer needed
    f.delete();
}
Also used : Pack200(java.util.jar.Pack200) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 12 with Pack200

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

the class Pack200Props method verifyDefaults.

private static void verifyDefaults() {
    Map<String, String> expectedDefaults = new HashMap<>();
    Packer p = Pack200.newPacker();
    expectedDefaults.put("com.sun.java.util.jar.pack.default.timezone", p.FALSE);
    expectedDefaults.put("com.sun.java.util.jar.pack.disable.native", p.FALSE);
    expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");
    expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");
    expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");
    expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable", "NH[PHPOHIIH]");
    expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable", "NH[PHHII]");
    expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);
    expectedDefaults.put(p.EFFORT, "5");
    expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);
    expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);
    expectedDefaults.put(p.SEGMENT_LIMIT, "-1");
    expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);
    Map<String, String> props = p.properties();
    int errors = 0;
    for (String key : expectedDefaults.keySet()) {
        String def = expectedDefaults.get(key);
        String x = props.get(key);
        if (x == null) {
            System.out.println("Error: key not found:" + key);
            errors++;
        } else {
            if (!def.equals(x)) {
                System.out.println("Error: key " + key + "\n  value expected: " + def + "\n  value obtained: " + x);
                errors++;
            }
        }
    }
    if (errors > 0) {
        throw new RuntimeException(errors + " error(s) encountered in default properties verification");
    }
}
Also used : HashMap(java.util.HashMap) Packer(java.util.jar.Pack200.Packer)

Example 13 with Pack200

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

the class TestExceptions method pack200Test3.

// test the Pack200.pack(JarInputStream, OutputStream);
static void pack200Test3() {
    List<PackTestJarInputStream> tlist = new ArrayList<PackTestJarInputStream>();
    try {
        // setup the test scenarios
        try {
            tlist.add(new PackTestJarInputStream((JarInputStream) null, null));
            tlist.add(new PackTestJarInputStream((JarInputStream) null, new ByteArrayOutputStream()));
            tlist.add(new PackTestJarInputStream(new JarInputStream(new FileInputStream(testJar)), null));
        } catch (Exception e) {
            throw new Error("Initialization error", e);
        }
        for (PackTestJarInputStream ti : tlist) {
            System.out.println(ti);
            try {
                Pack200.Packer p = Pack200.newPacker();
                p.pack(ti.getJarInputStream(), ti.getOutputStream());
            } catch (Exception e) {
                ti.checkException(e);
            }
        }
    } finally {
        // keep jprt happy
        for (PackTestJarInputStream ti : tlist) {
            if (ti != null) {
                ti.close();
            }
        }
    }
}
Also used : Pack200(java.util.jar.Pack200) JarInputStream(java.util.jar.JarInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 14 with Pack200

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

the class PackageVersionTest method verifyPack.

static void verifyPack(String filename, int expected_major, int expected_minor) {
    File jarFileName = new File("test.jar");
    jarFileName.delete();
    String[] jargs = { "cvf", jarFileName.getName(), filename };
    Utils.jar(jargs);
    JarFile jfin = null;
    try {
        jfin = new JarFile(jarFileName);
        Packer packer = Pack200.newPacker();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        packer.pack(jfin, baos);
        baos.flush();
        baos.close();
        byte[] buf = baos.toByteArray();
        int minor = buf[4] & 0x000000ff;
        int major = buf[5] & 0x000000ff;
        if (major != expected_major || minor != expected_minor) {
            String msg = String.format("test fails: expected:%d.%d but got %d.%d\n", expected_major, expected_minor, major, minor);
            throw new Error(msg);
        }
        System.out.println(filename + ": OK");
    } catch (IOException ioe) {
        throw new RuntimeException(ioe.getMessage());
    } finally {
        Utils.close((Closeable) jfin);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Packer(java.util.jar.Pack200.Packer)

Example 15 with Pack200

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

the class PackageVersionTest method verify6991164.

static void verify6991164() {
    Unpacker unpacker = Pack200.newUnpacker();
    String versionStr = unpacker.toString();
    String expected = "Pack200, Vendor: " + System.getProperty("java.vendor") + ", Version: " + JAVA7_PACKAGE_MAJOR_VERSION + "." + JAVA7_PACKAGE_MINOR_VERSION;
    if (!versionStr.equals(expected)) {
        System.out.println("Expected: " + expected);
        System.out.println("Obtained: " + versionStr);
        throw new RuntimeException("did not get expected string " + expected);
    }
}
Also used : 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