Path: blob/master/test/jdk/sun/security/tools/jarsigner/LargeJarEntry.java
41152 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* @modules jdk.jartool/sun.security.tools.jarsigner29* @run main/othervm -Xmx16m LargeJarEntry30* @author Sean Mullan31*/3233import java.io.File;34import java.io.FileOutputStream;35import java.util.jar.JarEntry;36import java.util.jar.JarOutputStream;37import java.util.zip.CRC32;3839public class LargeJarEntry {4041public static void main(String[] args) throws Exception {4243String srcDir = System.getProperty("test.src", ".");44String keystore = srcDir + "/JarSigning.keystore";45String jarName = "largeJarEntry.jar";4647// Set java.io.tmpdir to the current working dir (see 6474350)48System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));4950// first, create jar file with 8M uncompressed entry51// note, we set the max heap size to 8M in @run tag above52byte[] bytes = new byte[1000000];53CRC32 crc = new CRC32();54for (int i=0; i<8; i++) {55crc.update(bytes);56}57JarEntry je = new JarEntry("large");58je.setSize(8000000l);59je.setMethod(JarEntry.STORED);60je.setCrc(crc.getValue());61File file = new File(jarName);62FileOutputStream os = new FileOutputStream(file);63JarOutputStream jos = new JarOutputStream(os);64jos.setMethod(JarEntry.STORED);65jos.putNextEntry(je);66for (int i=0; i<8; i++) {67jos.write(bytes, 0, bytes.length);68}69jos.close();7071String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",72jarName, "b" };73// now, try to sign it74try {75sun.security.tools.jarsigner.Main.main(jsArgs);76} catch (OutOfMemoryError err) {77throw new Exception("Test failed with OutOfMemoryError", err);78} finally {79// remove jar file80file.delete();81}82}83}848586