Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/LargeJarEntry.java
38853 views
/*1* Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 6405538 647435026* @summary Make sure jar files with large entries (more than max heap size)27* can be signed28* @run main/othervm -Xmx8M LargeJarEntry29* @author Sean Mullan30*/3132import java.io.File;33import java.io.FileOutputStream;34import java.util.jar.JarEntry;35import java.util.jar.JarOutputStream;36import java.util.zip.CRC32;3738public class LargeJarEntry {3940public static void main(String[] args) throws Exception {4142String srcDir = System.getProperty("test.src", ".");43String keystore = srcDir + "/JarSigning.keystore";44String jarName = "largeJarEntry.jar";4546// Set java.io.tmpdir to the current working dir (see 6474350)47System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));4849// first, create jar file with 8M uncompressed entry50// note, we set the max heap size to 8M in @run tag above51byte[] bytes = new byte[1000000];52CRC32 crc = new CRC32();53for (int i=0; i<8; i++) {54crc.update(bytes);55}56JarEntry je = new JarEntry("large");57je.setSize(8000000l);58je.setMethod(JarEntry.STORED);59je.setCrc(crc.getValue());60File file = new File(jarName);61FileOutputStream os = new FileOutputStream(file);62JarOutputStream jos = new JarOutputStream(os);63jos.setMethod(JarEntry.STORED);64jos.putNextEntry(je);65for (int i=0; i<8; i++) {66jos.write(bytes, 0, bytes.length);67}68jos.close();6970String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",71jarName, "b" };72// now, try to sign it73try {74sun.security.tools.jarsigner.Main.main(jsArgs);75} catch (OutOfMemoryError err) {76throw new Exception("Test failed with OutOfMemoryError", err);77} finally {78// remove jar file79file.delete();80}81}82}838485