jdk/test/java/util/zip/ZipFile/TestZipFile.java
author sherman
Tue, 06 Dec 2016 14:44:12 -0800
changeset 42434 7fc88840baa5
parent 40684 2e37c119dc2a
permissions -rw-r--r--
8170828: test/java/util/zip/ZipFile/TestZipFile needs @modules to work with Method.setAccessible() Reviewed-by: martin, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34525
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     1
/*
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     4
 *
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     8
 *
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
40684
2e37c119dc2a 8164982: Fix legal notices in java/lang, java/net, java/util tests.
shurailine
parents: 34874
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
34525
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    13
 * accompanied this code).
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    14
 *
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    18
 *
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    21
 * questions.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    22
 */
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    23
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    24
/*
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    25
 * @test
34874
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
    26
 * @bug 8142508 8146431
42434
7fc88840baa5 8170828: test/java/util/zip/ZipFile/TestZipFile needs @modules to work with Method.setAccessible()
sherman
parents: 40684
diff changeset
    27
 * @modules java.base/java.util.zip:open
34525
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    28
 * @summary Tests various ZipFile apis
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    29
 * @run main/manual TestZipFile
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    30
 */
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    31
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    32
import java.io.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    33
import java.lang.reflect.Method;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    34
import java.nio.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    35
import java.nio.file.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    36
import java.nio.file.attribute.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    37
import java.util.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    38
import java.util.concurrent.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    39
import java.util.zip.*;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    40
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    41
public class TestZipFile {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    42
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    43
    private static Random r = new Random();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    44
    private static int    N = 50;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    45
    private static int    NN = 10;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    46
    private static int    ENUM = 10000;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    47
    private static int    ESZ = 10000;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    48
    private static ExecutorService executor = Executors.newFixedThreadPool(20);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    49
    private static Set<Path> paths = new HashSet<>();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    50
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    51
    static void realMain (String[] args) throws Throwable {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    52
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    53
        try {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    54
            for (int i = 0; i < N; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    55
                test(r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    56
                test(r.nextInt(ENUM), r.nextInt(ESZ), true, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    57
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    58
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    59
            for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    60
                test(r.nextInt(ENUM), 100000 + r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    61
                test(r.nextInt(ENUM), 100000 + r.nextInt(ESZ), true, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    62
                testCachedDelete();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    63
                testCachedOverwrite();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    64
                //test(r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    65
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    66
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    67
            test(70000, 1000, false, true);   // > 65536 entry number;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    68
            testDelete();                     // OPEN_DELETE
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    69
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    70
            executor.shutdown();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    71
            executor.awaitTermination(10, TimeUnit.MINUTES);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    72
        } finally {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    73
            for (Path path : paths) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    74
                Files.deleteIfExists(path);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    75
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    76
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    77
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    78
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    79
    static void test(int numEntry, int szMax, boolean addPrefix, boolean cleanOld) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    80
        String name = "zftest" + r.nextInt() + ".zip";
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    81
        Zip zip = new Zip(name, numEntry, szMax, addPrefix, cleanOld);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    82
        for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    83
            executor.submit(() -> doTest(zip));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    84
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    85
     }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    86
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    87
    // test scenario:
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    88
    // (1) open the ZipFile(zip) with OPEN_READ | OPEN_DELETE
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    89
    // (2) test the ZipFile works correctly
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    90
    // (3) check the zip is deleted after ZipFile gets closed
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    91
    static void testDelete() throws Throwable {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    92
        String name = "zftest" + r.nextInt() + ".zip";
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    93
        Zip zip = new Zip(name, r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    94
        try (ZipFile zf = new ZipFile(new File(zip.name),
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    95
                                      ZipFile.OPEN_READ | ZipFile.OPEN_DELETE ))
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    96
        {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    97
            doTest0(zip, zf);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    98
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
    99
        Path p = Paths.get(name);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   100
        if (Files.exists(p)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   101
            fail("Failed to delete " + name + " with OPEN_DELETE");
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   102
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   103
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   104
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   105
    // test scenario:
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   106
    // (1) keep a ZipFile(zip1) alive (in ZipFile's cache), dont close it
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   107
    // (2) delete zip1 and create zip2 with the same name the zip1 with zip2
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   108
    // (3) zip1 tests should fail, but no crash
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   109
    // (4) zip2 tasks should all get zip2, then pass normal testing.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   110
    static void testCachedDelete() throws Throwable {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   111
        String name = "zftest" + r.nextInt() + ".zip";
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   112
        Zip zip1 = new Zip(name, r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   113
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   114
        try (ZipFile zf = new ZipFile(zip1.name)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   115
            for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   116
                executor.submit(() -> verifyNoCrash(zip1));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   117
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   118
            // delete the "zip1"  and create a new one to test
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   119
            Zip zip2 = new Zip(name, r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   120
            /*
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   121
                System.out.println("========================================");
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   122
                System.out.printf("    zip1=%s, mt=%d, enum=%d%n    ->attrs=[key=%s, sz=%d, mt=%d]%n",
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   123
                    zip1.name, zip1.lastModified, zip1.entries.size(),
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   124
                    zip1.attrs.fileKey(), zip1.attrs.size(), zip1.attrs.lastModifiedTime().toMillis());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   125
                System.out.printf("    zip2=%s, mt=%d, enum=%d%n    ->attrs=[key=%s, sz=%d, mt=%d]%n",
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   126
                    zip2.name, zip2.lastModified, zip2.entries.size(),
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   127
                    zip2.attrs.fileKey(), zip2.attrs.size(), zip2.attrs.lastModifiedTime().toMillis());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   128
            */
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   129
            for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   130
                executor.submit(() -> doTest(zip2));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   131
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   132
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   133
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   134
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   135
   // overwrite the "zip1"  and create a new one to test. So the two zip files
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   136
   // have the same fileKey, but probably different lastModified()
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   137
    static void testCachedOverwrite() throws Throwable {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   138
        String name = "zftest" + r.nextInt() + ".zip";
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   139
        Zip zip1 = new Zip(name, r.nextInt(ENUM), r.nextInt(ESZ), false, true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   140
        try (ZipFile zf = new ZipFile(zip1.name)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   141
            for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   142
                executor.submit(() -> verifyNoCrash(zip1));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   143
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   144
            // overwrite the "zip1"  with new contents
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   145
            Zip zip2 = new Zip(name, r.nextInt(ENUM), r.nextInt(ESZ), false, false);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   146
            for (int i = 0; i < NN; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   147
                executor.submit(() -> doTest(zip2));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   148
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   149
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   150
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   151
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   152
    // just check the entries and contents. since the file has been either overwritten
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   153
    // or deleted/rewritten, we only care if it crahes or not.
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   154
    static void verifyNoCrash(Zip zip) throws RuntimeException {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   155
        try (ZipFile zf = new ZipFile(zip.name)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   156
            List<ZipEntry> zlist = new ArrayList(zip.entries.keySet());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   157
            String[] elist = zf.stream().map( e -> e.getName()).toArray(String[]::new);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   158
            if (!Arrays.equals(elist,
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   159
                               zlist.stream().map( e -> e.getName()).toArray(String[]::new)))
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   160
            {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   161
                //System.out.printf("++++++ LIST NG [%s] entries.len=%d, expected=%d+++++++%n",
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   162
                //                  zf.getName(), elist.length, zlist.size());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   163
                return;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   164
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   165
            for (ZipEntry ze : zlist) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   166
                byte[] zdata = zip.entries.get(ze);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   167
                ZipEntry e = zf.getEntry(ze.getName());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   168
                if (e != null) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   169
                    checkEqual(e, ze);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   170
                    if (!e.isDirectory()) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   171
                        // check with readAllBytes
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   172
                        try (InputStream is = zf.getInputStream(e)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   173
                            if (!Arrays.equals(zdata, is.readAllBytes())) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   174
                                //System.out.printf("++++++ BYTES NG  [%s]/[%s] ++++++++%n",
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   175
                                //                  zf.getName(), ze.getName());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   176
                            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   177
                        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   178
                    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   179
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   180
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   181
        } catch (Throwable t) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   182
            // t.printStackTrace();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   183
            // fail(t.toString());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   184
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   185
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   186
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   187
    static void checkEqual(ZipEntry x, ZipEntry y) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   188
        if (x.getName().equals(y.getName()) &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   189
            x.isDirectory() == y.isDirectory() &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   190
            x.getMethod() == y.getMethod() &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   191
            (x.getTime() / 2000) == y.getTime() / 2000 &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   192
            x.getSize() == y.getSize() &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   193
            x.getCompressedSize() == y.getCompressedSize() &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   194
            x.getCrc() == y.getCrc() &&
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   195
            x.getComment().equals(y.getComment())
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   196
        ) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   197
            pass();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   198
        } else {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   199
            fail(x + " not equal to " + y);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   200
            System.out.printf("      %s       %s%n", x.getName(), y.getName());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   201
            System.out.printf("      %d       %d%n", x.getMethod(), y.getMethod());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   202
            System.out.printf("      %d       %d%n", x.getTime(), y.getTime());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   203
            System.out.printf("      %d       %d%n", x.getSize(), y.getSize());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   204
            System.out.printf("      %d       %d%n", x.getCompressedSize(), y.getCompressedSize());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   205
            System.out.printf("      %d       %d%n", x.getCrc(), y.getCrc());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   206
            System.out.println("-----------------");
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   207
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   208
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   209
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   210
    static void doTest(Zip zip) throws RuntimeException {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   211
        //Thread me = Thread.currentThread();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   212
        try (ZipFile zf = new ZipFile(zip.name)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   213
            doTest0(zip, zf);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   214
        } catch (Throwable t) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   215
            throw new RuntimeException(t);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   216
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   217
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   218
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   219
    static void doTest0(Zip zip, ZipFile zf) throws Throwable {
34874
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   220
        // (0) check zero-length entry name, no AIOOBE
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   221
        try {
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   222
            check(zf.getEntry("") == null);;
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   223
        } catch (Throwable t) {
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   224
            unexpected(t);
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   225
        }
55a62be87e89 8146431: j.u.z.ZipFile.getEntry("") throws AIOOBE
sherman
parents: 34525
diff changeset
   226
34525
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   227
        List<ZipEntry> list = new ArrayList(zip.entries.keySet());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   228
        // (1) check entry list, in expected order
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   229
        if (!check(Arrays.equals(
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   230
                list.stream().map( e -> e.getName()).toArray(String[]::new),
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   231
                zf.stream().map( e -> e.getName()).toArray(String[]::new)))) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   232
            return;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   233
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   234
        // (2) shuffle, and check each entry and its bytes
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   235
        Collections.shuffle(list);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   236
        for (ZipEntry ze : list) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   237
            byte[] data = zip.entries.get(ze);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   238
            ZipEntry e = zf.getEntry(ze.getName());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   239
            checkEqual(e, ze);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   240
            if (!e.isDirectory()) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   241
                // check with readAllBytes
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   242
                try (InputStream is = zf.getInputStream(e)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   243
                    check(Arrays.equals(data, is.readAllBytes()));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   244
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   245
                // check with smaller sized buf
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   246
                try (InputStream is = zf.getInputStream(e)) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   247
                    byte[] buf = new byte[(int)e.getSize()];
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   248
                    int sz = r.nextInt((int)e.getSize()/4 + 1) + 1;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   249
                    int off = 0;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   250
                    int n;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   251
                    while ((n = is.read(buf, off, buf.length - off)) > 0) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   252
                        off += n;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   253
                    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   254
                    check(is.read() == -1);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   255
                    check(Arrays.equals(data, buf));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   256
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   257
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   258
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   259
        // (3) check getMetaInfEntryNames
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   260
        String[] metas = list.stream()
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   261
                             .map( e -> e.getName())
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   262
                             .filter( s -> s.startsWith("META-INF/"))
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   263
                             .sorted()
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   264
                             .toArray(String[]::new);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   265
        if (metas.length > 0) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   266
            // meta-inf entries
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   267
            Method getMetas = ZipFile.class.getDeclaredMethod("getMetaInfEntryNames");
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   268
            getMetas.setAccessible(true);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   269
            String[] names = (String[])getMetas.invoke(zf);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   270
            if (names == null) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   271
                fail("Failed to get metanames from " + zf);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   272
            } else {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   273
                Arrays.sort(names);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   274
                check(Arrays.equals(names, metas));
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   275
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   276
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   277
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   278
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   279
    private static class Zip {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   280
        String name;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   281
        Map<ZipEntry, byte[]> entries;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   282
        BasicFileAttributes attrs;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   283
        long lastModified;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   284
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   285
        Zip(String name, int num, int szMax, boolean prefix, boolean clean) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   286
            this.name = name;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   287
            entries = new LinkedHashMap<>(num);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   288
            try {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   289
                Path p = Paths.get(name);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   290
                if (clean) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   291
                    Files.deleteIfExists(p);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   292
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   293
                paths.add(p);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   294
            } catch (Exception x) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   295
                throw (RuntimeException)x;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   296
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   297
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   298
            try (FileOutputStream fos = new FileOutputStream(name);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   299
                 BufferedOutputStream bos = new BufferedOutputStream(fos);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   300
                 ZipOutputStream zos = new ZipOutputStream(bos))
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   301
            {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   302
                if (prefix) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   303
                    byte[] bytes = new byte[r.nextInt(1000)];
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   304
                    r.nextBytes(bytes);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   305
                    bos.write(bytes);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   306
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   307
                CRC32 crc = new CRC32();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   308
                for (int i = 0; i < num; i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   309
                    String ename = "entry-" + i + "-name-" + r.nextLong();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   310
                    ZipEntry ze = new ZipEntry(ename);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   311
                    int method = r.nextBoolean() ? ZipEntry.STORED : ZipEntry.DEFLATED;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   312
                    writeEntry(zos, crc, ze, ZipEntry.STORED, szMax);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   313
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   314
                // add some manifest entries
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   315
                for (int i = 0; i < r.nextInt(20); i++) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   316
                    String meta = "META-INF/" + "entry-" + i + "-metainf-" + r.nextLong();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   317
                    ZipEntry ze = new ZipEntry(meta);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   318
                    writeEntry(zos, crc, ze, ZipEntry.STORED, szMax);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   319
                }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   320
            } catch (Exception x) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   321
                throw (RuntimeException)x;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   322
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   323
            try {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   324
                this.attrs = Files.readAttributes(Paths.get(name), BasicFileAttributes.class);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   325
                this.lastModified = new File(name).lastModified();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   326
            } catch (Exception x) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   327
                throw (RuntimeException)x;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   328
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   329
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   330
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   331
        private void writeEntry(ZipOutputStream zos, CRC32 crc,
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   332
                                ZipEntry ze, int method, int szMax)
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   333
            throws IOException
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   334
        {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   335
            ze.setMethod(method);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   336
            byte[] data = new byte[r.nextInt(szMax + 1)];
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   337
            r.nextBytes(data);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   338
            if (method == ZipEntry.STORED) {  // must set size/csize/crc
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   339
                ze.setSize(data.length);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   340
                ze.setCompressedSize(data.length);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   341
                crc.reset();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   342
                crc.update(data);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   343
                ze.setCrc(crc.getValue());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   344
            }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   345
            ze.setTime(System.currentTimeMillis());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   346
            ze.setComment(ze.getName());
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   347
            zos.putNextEntry(ze);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   348
            zos.write(data);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   349
            zos.closeEntry();
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   350
            entries.put(ze, data);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   351
        }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   352
    }
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   353
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   354
    //--------------------- Infrastructure ---------------------------
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   355
    static volatile int passed = 0, failed = 0;
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   356
    static void pass() {passed++;}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   357
    static void pass(String msg) {System.out.println(msg); passed++;}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   358
    static void fail() {failed++; Thread.dumpStack();}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   359
    static void fail(String msg) {System.out.println(msg); fail();}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   360
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   361
    static void unexpected(Throwable t, String msg) {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   362
        System.out.println(msg); failed++; t.printStackTrace();}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   363
    static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   364
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   365
    public static void main(String[] args) throws Throwable {
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   366
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   367
        System.out.println("\nPassed = " + passed + " failed = " + failed);
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   368
        if (failed > 0) throw new AssertionError("Some tests failed");}
14d2d84cae6d 8142508: To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk
sherman
parents:
diff changeset
   369
}