1113N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1113N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1113N/A *
1113N/A * This code is free software; you can redistribute it and/or modify it
1113N/A * under the terms of the GNU General Public License version 2 only, as
1113N/A * published by the Free Software Foundation.
1113N/A *
1113N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1113N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1113N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1113N/A * version 2 for more details (a copy is included in the LICENSE file that
1113N/A * accompanied this code).
1113N/A *
1113N/A * You should have received a copy of the GNU General Public License version
1113N/A * 2 along with this work; if not, write to the Free Software Foundation,
1113N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1113N/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.
1113N/A */
1113N/A
1113N/A/**
1113N/A * A simple class to create our erring Jar with a very long Main-Class
1113N/A * attribute in the manifest.
1113N/A */
1113N/Aimport java.io.ByteArrayOutputStream;
1113N/Aimport java.io.FileOutputStream;
1113N/Aimport java.io.IOException;
1113N/Aimport java.io.PrintStream;
1113N/Aimport java.util.zip.CRC32;
1113N/Aimport java.util.zip.CheckedOutputStream;
1113N/Aimport java.util.zip.ZipEntry;
1113N/Aimport java.util.zip.ZipOutputStream;
1113N/Apublic class ZipMeUp {
1113N/A
1113N/A static final CRC32 crc = new CRC32();
1113N/A
1113N/A private static String SOME_KLASS = ".Some";
1113N/A
1113N/A static byte[] getManifestAsBytes(int nchars) throws IOException {
1113N/A crc.reset();
1113N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
1113N/A CheckedOutputStream cos = new CheckedOutputStream(baos, crc);
1113N/A PrintStream ps = new PrintStream(cos);
1113N/A ps.println("Manifest-Version: 1.0");
1113N/A ps.print("Main-Class: ");
1113N/A for (int i = 0 ; i < nchars - SOME_KLASS.length() ; i++) {
1113N/A ps.print(i%10);
1113N/A }
1113N/A ps.println(SOME_KLASS);
1113N/A cos.flush();
1113N/A cos.close();
1113N/A ps.close();
1113N/A return baos.toByteArray();
1113N/A }
1113N/A
1113N/A /**
1113N/A * The arguments are: filename_to_create length
1113N/A * @param args
1113N/A * @throws java.lang.Exception
1113N/A */
1113N/A public static void main(String...args) throws Exception {
1113N/A FileOutputStream fos = new FileOutputStream(args[0]);
1113N/A ZipOutputStream zos = new ZipOutputStream(fos);
1113N/A byte[] manifest = getManifestAsBytes(Integer.parseInt(args[1]));
1113N/A ZipEntry ze = new ZipEntry("META-INF/MANIFEST.MF");
1113N/A ze.setMethod(ZipEntry.STORED);
1113N/A ze.setSize(manifest.length);
1113N/A ze.setCompressedSize(manifest.length);
1113N/A ze.setCrc(crc.getValue());
1113N/A ze.setTime(System.currentTimeMillis());
1113N/A zos.putNextEntry(ze);
1113N/A zos.write(manifest);
1113N/A zos.flush();
1113N/A
1113N/A // add a zero length class
1113N/A ze = new ZipEntry(SOME_KLASS + ".class");
1113N/A ze.setMethod(ZipEntry.STORED);
1113N/A ze.setSize(0);
1113N/A ze.setCompressedSize(0);
1113N/A ze.setCrc(0);
1113N/A ze.setTime(System.currentTimeMillis());
1113N/A zos.putNextEntry(ze);
1113N/A zos.flush();
1113N/A zos.closeEntry();
1113N/A zos.close();
1113N/A System.exit(0);
1113N/A }
1113N/A}