Package org.apache.harmony.pack200

Examples of org.apache.harmony.pack200.PackingOptions


    public void testStripDebug() throws IOException, Pack200Exception, URISyntaxException {
        in = new JarFile(new File(Archive.class
                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
        file = File.createTempFile("sql", ".pack");
        out = new FileOutputStream(file);
        PackingOptions options = new PackingOptions();
        options.setGzip(false);
        options.setStripDebug(true);
        Archive archive = new Archive(in, out, options);
        archive.pack();
        in.close();
        out.close();
View Full Code Here


        // Don't pass any
        in = new JarFile(new File(Archive.class
                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
        File file0 = File.createTempFile("sql", ".pack");
        out = new FileOutputStream(file0);
        PackingOptions options = new PackingOptions();
        options.setGzip(false);
        Archive archive = new Archive(in, out, options);
        archive.pack();
        in.close();
        out.close();

        // Pass one file
        in = new JarFile(new File(Archive.class
                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
        file = File.createTempFile("sql", ".pack");
        out = new FileOutputStream(file);
        options = new PackingOptions();
        options.setGzip(false);
        options.addPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class");
        assertTrue(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class"));
        archive = new Archive(in, out, options);
        archive.pack();
        in.close();
        out.close();

        // Pass a whole directory
        in = new JarFile(new File(Archive.class
                .getResource("/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
        File file2 = File.createTempFile("sql", ".pack");
        out = new FileOutputStream(file2);
        options = new PackingOptions();
        options.setGzip(false);
        options.addPassFile("bin/test/org/apache/harmony/sql/tests/java/sql");
        assertTrue(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.class"));
        assertFalse(options.isPassFile("bin/test/org/apache/harmony/sql/tests/java/sqldata/SqlData.class"));
        archive = new Archive(in, out, options);
        archive.pack();
        in.close();
        out.close();
View Full Code Here

        in = new JarFile(new File(Archive.class.getResource(
                "/org/apache/harmony/pack200/tests/annotationsUnpacked.jar")
                .toURI()));
        file = File.createTempFile("annotations", ".pack");
        out = new FileOutputStream(file);
        PackingOptions options = new PackingOptions();
        options.setGzip(false);
        new Archive(in, out, options).pack();
        in.close();
        out.close();

        // now unpack
View Full Code Here

        in = new JarFile(new File(Archive.class.getResource(
                "/org/apache/harmony/pack200/tests/annotations.jar").toURI()));
        file = File.createTempFile("annotations", ".pack");
        file.deleteOnExit();
        out = new FileOutputStream(file);
        PackingOptions options = new PackingOptions();
        options.setGzip(false);
        new Archive(in, out, options).pack();
        in.close();
        out.close();

        // now unpack
View Full Code Here

        File f1 = new File(Archive.class.getResource(
                "/org/apache/harmony/pack200/tests/jndi.jar").toURI());
        in = new JarFile(f1);
        file = File.createTempFile("jndiE0", ".pack");
        out = new FileOutputStream(file);
        PackingOptions options = new PackingOptions();
        options.setGzip(false);
        options.setEffort(0);
        Archive archive = new Archive(in, out, options);
        archive.pack();
        in.close();
        out.close();
        compareFiles(new JarFile(f1), new JarFile(file));
View Full Code Here

public class Main {

    public static void main(String args[]) throws Exception {
        String inputFileName = null;
        String outputFileName = null;
        PackingOptions options = new PackingOptions();
        String value = null;

        for (int i = 0; i < args.length; i++) {
            if ("--help".equals(args[i]) || "-help".equals(args[i])
                    || "-h".equals(args[i]) || "-?".equals(args[i])) {
                printHelp();
                return;
            } else if ("-V".equals(args[i]) || "--version".equals(args[i])) {
                printVersion();
                return;
            } else if ("-g".equals(args[i]) || "--no-gzip".equals(args[i])) {
                options.setGzip(false);
            } else if ("--gzip".equals(args[i])) {
                options.setGzip(true);
            } else if ("-G".equals(args[i]) || "--strip-debug".equals(args[i])) {
                options.setStripDebug(true);
            } else if ("-O".equals(args[i])
                    || "--no-keep-file-order".equals(args[i])) {
                options.setKeepFileOrder(false);
            } else if ("--keep-file-order".equals(args[i])) {
                options.setKeepFileOrder(true);
            } else if (args[i].startsWith("-S")) {
                value = args[i].substring(2);
                if(value.length() == 0) {
                    if(i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -S ?");
                        printUsage();
                        return;
                    }
                }
                options.setSegmentLimit(Long.parseLong(value));
            } else if (args[i].startsWith("--segment-limit=")) {
                options.setSegmentLimit(Long.parseLong(args[i].substring(16)));
            } else if (args[i].startsWith("-E")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -E ?");
                        printUsage();
                        return;
                    }
                }
                options.setEffort(Integer.parseInt(value));
            } else if (args[i].startsWith("--effort=")) {
                options.setEffort(Integer.parseInt(args[i].substring(9)));
            } else if (args[i].startsWith("-H")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -H ?");
                        printUsage();
                        return;
                    }
                }
                options.setDeflateHint(value);
            } else if (args[i].startsWith("--deflate-hint=")) {
                options.setDeflateHint(args[i].substring(15));
            } else if (args[i].startsWith("-m")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -m ?");
                        printUsage();
                        return;
                    }
                }
                options.setModificationTime(value);
            } else if (args[i].startsWith("--modification-time=")) {
                options.setModificationTime(args[i].substring(20));
            } else if (args[i].startsWith("-P")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -P ?");
                        printUsage();
                        return;
                    }
                }
                options.addPassFile(value);
            } else if (args[i].startsWith("--pass-file=")) {
                options.addPassFile(args[i].substring(12));
            } else if (args[i].startsWith("-U")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -U ?");
                        printUsage();
                        return;
                    }
                }
                options.setUnknownAttributeAction(value);
            } else if (args[i].startsWith("--unknown-attribute=")) {
                options.setUnknownAttributeAction(args[i].substring(20));
            } else if (args[i].startsWith("-C")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -C ?");
                        printUsage();
                        return;
                    }
                }
                String[] nameEqualsAction = value.split("=");
                options.addClassAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("--class-attribute=")) {
                String[] nameEqualsAction = args[i].substring(18).split("=");
                options.addClassAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("-F")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -F ?");
                        printUsage();
                        return;
                    }
                }
                String[] nameEqualsAction = value.split("=");
                options.addFieldAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("--field-attribute=")) {
                String[] nameEqualsAction = args[i].substring(18).split("=");
                options.addFieldAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("-M")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -M ?");
                        printUsage();
                        return;
                    }
                }
                String[] nameEqualsAction = value.split("=");
                options.addMethodAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("--method-attribute=")) {
                String[] nameEqualsAction = args[i].substring(19).split("=");
                options.addMethodAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("-D")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -D ?");
                        printUsage();
                        return;
                    }
                }
                String[] nameEqualsAction = value.split("=");
                options.addCodeAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if (args[i].startsWith("--code-attribute=")) {
                String[] nameEqualsAction = args[i].substring(17).split("=");
                options.addCodeAttributeAction(nameEqualsAction[0],
                        nameEqualsAction[1]);
            } else if ("-v".equals(args[i]) || "--verbose".equals(args[i])) {
                options.setVerbose(true);
                options.setQuiet(false);
            } else if ("-q".equals(args[i]) || "--quiet".equals(args[i])) {
                options.setQuiet(true);
                options.setVerbose(false);
            } else if (args[i].startsWith("-l")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -l ?");
                        printUsage();
                        return;
                    }
                }
                options.setLogFile(value);
            } else if (args[i].startsWith("--log-file=")) {
                options.setLogFile(args[i].substring(11));
            } else if ("-r".equals(args[i]) || "--repack".equals(args[i])) {
                options.setRepack(true);
            } else if (args[i].startsWith("-f")) {
                value = args[i].substring(2);
                if (value.length() == 0) {
                    if (i + 1 < args.length) {
                        value = args[++i];
                    } else {
                        printErrorMessage("Bad argument: -f ?");
                        printUsage();
                        return;
                    }
                }
                loadPackProperties(value, options);
            } else if (args[i].startsWith("--config-file=")) {
                loadPackProperties(args[i].substring(14), options);
            } else {
                outputFileName = args[i];
                if (args.length > i + 1) {
                    if (args.length == i + 2) {
                        inputFileName = args[++i];
                    } else {
                        printUsage();
                        return;
                    }
                }
            }
        }

        if (options.isRepack()) {
            repack(inputFileName, outputFileName, options);
        } else {
            pack(inputFileName, outputFileName, options);
        }
    }
View Full Code Here

    private void checkDecode(byte[] data, long[] expectedResult, Codec codec)
            throws IOException, Pack200Exception {
        InputStream in = new ByteArrayInputStream(data);

        int[] result = new PopulationCodec(codec, codec, codec).decodeInts(
                expectedResult.length, in);
        assertEquals(expectedResult.length, result.length);
        for (int i = 0; i < expectedResult.length; i++) {
            assertEquals(expectedResult[i], result[i]);
        }
View Full Code Here

  }

  private void checkDecode(byte[] data, long[] expectedResult, Codec codec) throws IOException, Pack200Exception {
    InputStream in = new ByteArrayInputStream(data );
   
    long[] result = new PopulationCodec(codec,codec,codec).decode(expectedResult.length,in);
    assertEquals(expectedResult.length,result.length);
    for(int i=0;i<expectedResult.length;i++) {
      assertEquals(expectedResult[i],result[i]);
    }
    assertEquals(0,in.available());
View Full Code Here

    private void checkDecode(byte[] data, long[] expectedResult, Codec codec)
            throws IOException, Pack200Exception {
        InputStream in = new ByteArrayInputStream(data);

        long[] result = new PopulationCodec(codec, codec, codec).decode(
                expectedResult.length, in);
        assertEquals(expectedResult.length, result.length);
        for (int i = 0; i < expectedResult.length; i++) {
            assertEquals(expectedResult[i], result[i]);
        }
View Full Code Here

        assertFalse(byte2s.encodes(192));
        assertFalse(byte2s.encodes(256));
    }

    public void testRunCodec() throws Exception {
        RunCodec runCodec = new RunCodec(1, Codec.UNSIGNED5, Codec.BYTE1);
        ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {
                (byte) 192, 0, (byte) 192, 0 });
        assertEquals(192, runCodec.decode(bais));
        assertEquals(192, runCodec.decode(bais));
        assertEquals(0, runCodec.decode(bais));
        assertEquals(0, bais.available());
        runCodec = new RunCodec(1, Codec.BYTE1, Codec.UNSIGNED5);
        bais = new ByteArrayInputStream(new byte[] { (byte) 192, 0, (byte) 192,
                0 });
        assertEquals(192, runCodec.decode(bais));
        assertEquals(0, runCodec.decode(bais));
        assertEquals(192, runCodec.decode(bais));
        assertEquals(0, bais.available());
    }
View Full Code Here

TOP

Related Classes of org.apache.harmony.pack200.PackingOptions

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.