LargeJarEntry.java revision 2362
0N/A/*
2362N/A * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6405538 6474350
0N/A * @summary Make sure jar files with large entries (more than max heap size)
0N/A * can be signed
0N/A * @run main/othervm -Xmx8M LargeJarEntry
0N/A * @author Sean Mullan
0N/A */
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.FileOutputStream;
0N/Aimport java.util.jar.JarEntry;
0N/Aimport java.util.jar.JarOutputStream;
0N/Aimport java.util.zip.CRC32;
0N/Aimport sun.security.tools.JarSigner;
0N/A
0N/Apublic class LargeJarEntry {
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A
0N/A String srcDir = System.getProperty("test.src", ".");
0N/A String keystore = srcDir + "/JarSigning.keystore";
0N/A String jarName = "largeJarEntry.jar";
0N/A
0N/A // Set java.io.tmpdir to the current working dir (see 6474350)
0N/A System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));
0N/A
0N/A // first, create jar file with 8M uncompressed entry
0N/A // note, we set the max heap size to 8M in @run tag above
0N/A byte[] bytes = new byte[1000000];
0N/A CRC32 crc = new CRC32();
0N/A for (int i=0; i<8; i++) {
0N/A crc.update(bytes);
0N/A }
0N/A JarEntry je = new JarEntry("large");
0N/A je.setSize(8000000l);
0N/A je.setMethod(JarEntry.STORED);
0N/A je.setCrc(crc.getValue());
0N/A File file = new File(jarName);
0N/A FileOutputStream os = new FileOutputStream(file);
0N/A JarOutputStream jos = new JarOutputStream(os);
0N/A jos.setMethod(JarEntry.STORED);
0N/A jos.putNextEntry(je);
0N/A for (int i=0; i<8; i++) {
0N/A jos.write(bytes, 0, bytes.length);
0N/A }
0N/A jos.close();
0N/A
0N/A String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
0N/A jarName, "b" };
0N/A // now, try to sign it
0N/A try {
0N/A JarSigner.main(jsArgs);
0N/A } catch (OutOfMemoryError err) {
0N/A throw new Exception("Test failed with OutOfMemoryError", err);
0N/A } finally {
0N/A // remove jar file
0N/A file.delete();
0N/A }
0N/A }
0N/A}