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