test/jdk/tools/pack200/PackTestZip64.java
author chegar
Thu, 17 Oct 2019 20:27:44 +0100
branchdatagramsocketimpl-branch
changeset 58677 13588c901957
parent 47216 71c04702a3d5
permissions -rw-r--r--
Initial changes for datagramsocketimpl-branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22575
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     1
/*
31725
8d753f6f3faf 8130402: Mark intermittently failing test: tools/pack200/PackTestZip64.java
amlu
parents: 28255
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
22575
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     4
 *
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     8
 *
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    13
 * accompanied this code).
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    14
 *
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    18
 *
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    21
 * questions.
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    22
 */
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    23
import java.io.*;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    24
import java.util.ArrayList;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    25
import java.util.Collections;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    26
import java.util.Enumeration;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    27
import java.util.List;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    28
import java.util.jar.JarEntry;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    29
import java.util.jar.JarFile;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    30
import java.util.jar.JarInputStream;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    31
import java.util.jar.JarOutputStream;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    32
import java.util.zip.ZipEntry;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    33
/*
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    34
 * @test
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    35
 * @bug 8029646
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    36
 * @summary tests that native unpacker produces the same result as Java one
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    37
 * @compile -XDignore.symbol.file Utils.java PackTestZip64.java
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    38
 * @run main PackTestZip64
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    39
 * @author kizune
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    40
 */
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    41
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    42
public class PackTestZip64 {
32142
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    43
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    44
    private static final boolean bigJarEnabled
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    45
            = Boolean.getBoolean("PackTestZip64.enableBigJar");
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    46
22575
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    47
    public static void main(String... args) throws Exception {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    48
        testPacking();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    49
        Utils.cleanup();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    50
    }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    51
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    52
    // 1KB buffer is enough to copy jar content
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    53
    private static final byte[] BUFFER = new byte[1024];
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    54
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    55
    static void testPacking() throws IOException {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    56
        File testFile = new File("tools_java.jar");
32142
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    57
        if (bigJarEnabled) {
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    58
            // Add a large number of small files to the golden jar
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    59
            generateLargeJar(testFile, Utils.getGoldenJar());
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    60
        } else {
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    61
            // make a copy of the test specimen to local directory
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    62
            Utils.copyFile(Utils.getGoldenJar(), testFile);
bb38b4bc2063 8079769: tools/pack200/PackTestZip64.java may timeout at preparing the large test file
amlu
parents: 31725
diff changeset
    63
        }
22575
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    64
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    65
        List<String> cmdsList = new ArrayList<>();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    66
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    67
        // Repack file to get the Java-based result
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    68
        cmdsList.add(Utils.getPack200Cmd());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    69
        cmdsList.add("--repack");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    70
        cmdsList.add(testFile.getName());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    71
        Utils.runExec(cmdsList);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    72
        cmdsList.clear();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    73
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    74
        // Pack file with pack200 and unpack in with unpack200
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    75
        File packedFile = new File("tools.pack.gz");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    76
        cmdsList.add(Utils.getPack200Cmd());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    77
        cmdsList.add(packedFile.getName());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    78
        cmdsList.add(testFile.getName());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    79
        Utils.runExec(cmdsList);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    80
        cmdsList.clear();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    81
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    82
        File unpackedFile = new File("tools_native.jar");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    83
        cmdsList.add(Utils.getUnpack200Cmd());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    84
        cmdsList.add(packedFile.getName());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    85
        cmdsList.add(unpackedFile.getName());
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    86
        Utils.runExec(cmdsList);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    87
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    88
        // Compare files binary
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    89
        compareTwoFiles(testFile, unpackedFile);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    90
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    91
        // Cleaning up generated files
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    92
        testFile.delete();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    93
        packedFile.delete();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    94
        unpackedFile.delete();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    95
    }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    96
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    97
    static void compareTwoFiles(File src, File dst) throws IOException {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    98
        if (!src.exists()) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
    99
            throw new IOException("File " + src.getName() + " does not exist!");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   100
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   101
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   102
        if(!dst.exists()) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   103
            throw new IOException("File " + dst.getName() + " does not exist!");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   104
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   105
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   106
        BufferedInputStream srcis, dstis;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   107
        srcis = new BufferedInputStream(new FileInputStream(src));
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   108
        dstis = new BufferedInputStream(new FileInputStream(dst));
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   109
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   110
        int s = 0, d, pos = 0;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   111
        while (s != -1) { // Checking of just one result for EOF is enough
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   112
            s = srcis.read();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   113
            d = dstis.read();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   114
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   115
            if (s != d) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   116
                throw new IOException("Files are differ starting at position: "
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   117
                + Integer.toHexString(pos));
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   118
            }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   119
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   120
            pos++;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   121
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   122
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   123
        srcis.close();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   124
        dstis.close();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   125
    }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   126
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   127
    static void generateLargeJar(File result, File source) throws IOException {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   128
        if (result.exists()) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   129
            result.delete();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   130
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   131
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   132
        try (JarOutputStream copyTo = new JarOutputStream(new FileOutputStream(result));
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   133
             JarFile srcJar = new JarFile(source)) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   134
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   135
            for (JarEntry je : Collections.list(srcJar.entries())) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   136
                copyTo.putNextEntry(je);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   137
                if (!je.isDirectory()) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   138
                    copyStream(srcJar.getInputStream(je), copyTo);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   139
                }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   140
                copyTo.closeEntry();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   141
            }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   142
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   143
            int many = Short.MAX_VALUE * 2 + 2;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   144
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   145
            for (int i = 0 ; i < many ; i++) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   146
                JarEntry e = new JarEntry("F-" + i + ".txt");
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   147
                copyTo.putNextEntry(e);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   148
            }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   149
            copyTo.flush();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   150
            copyTo.close();
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   151
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   152
    }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   153
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   154
    static void copyStream(InputStream in, OutputStream out) throws IOException {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   155
        int bytesRead;
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   156
        while ((bytesRead = in.read(BUFFER))!= -1) {
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   157
            out.write(BUFFER, 0, bytesRead);
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   158
        }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   159
    }
0c2768190cf4 8029646: [pack200] should support the new zip64 format.
kizune
parents:
diff changeset
   160
}