source: trunk/openjdk/jdk/test/tools/launcher/ZipMeUp.java

Last change on this file was 278, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b22 from branches/vendor/oracle.

File size: 3.2 KB
Line 
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 * The arguments are: filename_to_create length
60 * @param args
61 * @throws java.lang.Exception
62 */
63 public static void main(String...args) throws Exception {
64 FileOutputStream fos = new FileOutputStream(args[0]);
65 ZipOutputStream zos = new ZipOutputStream(fos);
66 byte[] manifest = getManifestAsBytes(Integer.parseInt(args[1]));
67 ZipEntry ze = new ZipEntry("META-INF/MANIFEST.MF");
68 ze.setMethod(ZipEntry.STORED);
69 ze.setSize(manifest.length);
70 ze.setCompressedSize(manifest.length);
71 ze.setCrc(crc.getValue());
72 ze.setTime(System.currentTimeMillis());
73 zos.putNextEntry(ze);
74 zos.write(manifest);
75 zos.flush();
76
77 // add a zero length class
78 ze = new ZipEntry(SOME_KLASS + ".class");
79 ze.setMethod(ZipEntry.STORED);
80 ze.setSize(0);
81 ze.setCompressedSize(0);
82 ze.setCrc(0);
83 ze.setTime(System.currentTimeMillis());
84 zos.putNextEntry(ze);
85 zos.flush();
86 zos.closeEntry();
87 zos.close();
88 System.exit(0);
89 }
90}
Note: See TracBrowser for help on using the repository browser.