1/* 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/** 25 * A simple class to create our erring Jar with a very long Main-Class 26 * attribute in the manifest. 27 */ 28import java.io.ByteArrayOutputStream; 29import java.io.FileOutputStream; 30import java.io.IOException; 31import java.io.PrintStream; 32import java.util.zip.CRC32; 33import java.util.zip.CheckedOutputStream; 34import java.util.zip.ZipEntry; 35import java.util.zip.ZipOutputStream; 36public class ZipMeUp { 37 38 static final CRC32 crc = new CRC32(); 39 40 private static String SOME_KLASS = ".Some"; 41 42 static byte[] getManifestAsBytes(int nchars) throws IOException { 43 crc.reset(); 44 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 45 CheckedOutputStream cos = new CheckedOutputStream(baos, crc); 46 PrintStream ps = new PrintStream(cos); 47 ps.println("Manifest-Version: 1.0"); 48 ps.print("Main-Class: "); 49 for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) { 50 ps.print(i%10); 51 } 52 ps.println(SOME_KLASS); 53 cos.flush(); 54 cos.close(); 55 ps.close(); 56 return baos.toByteArray(); 57 } 58 59 /** 60 * The arguments are: filename_to_create length 61 * @param args 62 * @throws java.lang.Exception 63 */ 64 public static void main(String...args) throws Exception { 65 FileOutputStream fos = new FileOutputStream(args[0]); 66 ZipOutputStream zos = new ZipOutputStream(fos); 67 byte[] manifest = getManifestAsBytes(Integer.parseInt(args[1])); 68 ZipEntry ze = new ZipEntry("META-INF/MANIFEST.MF"); 69 ze.setMethod(ZipEntry.STORED); 70 ze.setSize(manifest.length); 71 ze.setCompressedSize(manifest.length); 72 ze.setCrc(crc.getValue()); 73 ze.setTime(System.currentTimeMillis()); 74 zos.putNextEntry(ze); 75 zos.write(manifest); 76 zos.flush(); 77 78 // add a zero length class 79 ze = new ZipEntry(SOME_KLASS + ".class"); 80 ze.setMethod(ZipEntry.STORED); 81 ze.setSize(0); 82 ze.setCompressedSize(0); 83 ze.setCrc(0); 84 ze.setTime(System.currentTimeMillis()); 85 zos.putNextEntry(ze); 86 zos.flush(); 87 zos.closeEntry(); 88 zos.close(); 89 System.exit(0); 90 } 91} 92