Path: blob/master/test/jdk/tools/launcher/ZipMeUp.java
41144 views
/*1* Copyright (c) 2008, 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* A simple class to create our erring Jar with a very long Main-Class25* attribute in the manifest.26*/27import java.io.ByteArrayOutputStream;28import java.io.FileOutputStream;29import java.io.IOException;30import java.io.PrintStream;31import java.util.zip.CRC32;32import java.util.zip.CheckedOutputStream;33import java.util.zip.ZipEntry;34import java.util.zip.ZipOutputStream;35public class ZipMeUp {3637static final CRC32 crc = new CRC32();3839private static String SOME_KLASS = ".Some";4041static byte[] getManifestAsBytes(int nchars) throws IOException {42crc.reset();43ByteArrayOutputStream baos = new ByteArrayOutputStream();44CheckedOutputStream cos = new CheckedOutputStream(baos, crc);45PrintStream ps = new PrintStream(cos);46ps.println("Manifest-Version: 1.0");47ps.print("Main-Class: ");48for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) {49ps.print(i%10);50}51ps.println(SOME_KLASS);52cos.flush();53cos.close();54ps.close();55return baos.toByteArray();56}5758/**59* The arguments are: filename_to_create length60* @param args61* @throws java.lang.Exception62*/63public static void main(String...args) throws Exception {64FileOutputStream fos = new FileOutputStream(args[0]);65ZipOutputStream zos = new ZipOutputStream(fos);66byte[] manifest = getManifestAsBytes(Integer.parseInt(args[1]));67ZipEntry ze = new ZipEntry("META-INF/MANIFEST.MF");68ze.setMethod(ZipEntry.STORED);69ze.setSize(manifest.length);70ze.setCompressedSize(manifest.length);71ze.setCrc(crc.getValue());72ze.setTime(System.currentTimeMillis());73zos.putNextEntry(ze);74zos.write(manifest);75zos.flush();7677// add a zero length class78ze = new ZipEntry(SOME_KLASS + ".class");79ze.setMethod(ZipEntry.STORED);80ze.setSize(0);81ze.setCompressedSize(0);82ze.setCrc(0);83ze.setTime(System.currentTimeMillis());84zos.putNextEntry(ze);85zos.flush();86zos.closeEntry();87zos.close();88System.exit(0);89}90}919293