java.util.jar.JarOutputStream#setMethod ( )源码实例Demo

下面列出了java.util.jar.JarOutputStream#setMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: URLMapperTest.java
/**
 * Check that jar: URLs are correctly mapped back into JarFileSystem resources.
 * @see "#39190"
 */
public void testJarMapping() throws Exception {
    clearWorkDir();
    File workdir = getWorkDir();
    File jar = new File(workdir, "test.jar");
    String textPath = "x.txt";
    OutputStream os = new FileOutputStream(jar);
    try {
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(ZipEntry.STORED);
        JarEntry entry = new JarEntry(textPath);
        entry.setSize(0L);
        entry.setTime(System.currentTimeMillis());
        entry.setCrc(new CRC32().getValue());
        jos.putNextEntry(entry);
        jos.flush();
        jos.close();
    } finally {
        os.close();
    }
    assertTrue("JAR was created", jar.isFile());
    assertTrue("JAR is not empty", jar.length() > 0L);
    JarFileSystem jfs = new JarFileSystem();
    jfs.setJarFile(jar);
    Repository.getDefault().addFileSystem(jfs);
    FileObject rootFO = jfs.getRoot();
    FileObject textFO = jfs.findResource(textPath);
    assertNotNull("JAR contains a/b.txt", textFO);
    String rootS = "jar:" + BaseUtilities.toURI(jar) + "!/";
    URL rootU = new URL(rootS);
    URL textU = new URL(rootS + textPath);
    assertEquals("correct FO -> URL for root", rootU, URLMapper.findURL(rootFO, URLMapper.EXTERNAL));
    assertEquals("correct FO -> URL for " + textPath, textU, URLMapper.findURL(textFO, URLMapper.EXTERNAL));
    assertTrue("correct URL -> FO for root", Arrays.asList(URLMapper.findFileObjects(rootU)).contains(rootFO));
    assertTrue("correct URL -> FO for " + textPath, Arrays.asList(URLMapper.findFileObjects(textU)).contains(textFO));
}
 
源代码2 项目: dragonwell8_jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码3 项目: TencentKona-8   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码4 项目: jdk8u60   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码5 项目: openjdk-jdk8u   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码6 项目: openjdk-jdk8u-backup   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码7 项目: openjdk-jdk9   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码8 项目: jdk8u-jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码9 项目: hottub   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码10 项目: openjdk-8-source   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码11 项目: openjdk-8   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码12 项目: jdk8u_jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码13 项目: jdk8u-jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码14 项目: jdk8u-dev-jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }