jdk/test/java/util/zip/LargeZip.java
author michaelm
Fri, 02 Oct 2009 13:57:41 +0100
changeset 3952 dc329398de30
parent 2438 21c111b51aa8
child 5506 202f599c92aa
permissions -rw-r--r--
6870935: DIGEST proxy authentication fails to connect to URLs with no trailing slash Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     1
/*
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     4
 *
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    10
 *
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    15
 * accompanied this code).
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    16
 *
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    20
 *
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    23
 * have any questions.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    24
 */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    25
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    26
import java.io.*;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    27
import java.nio.*;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    28
import java.util.*;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    29
import java.util.zip.*;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    30
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    31
public class LargeZip {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    32
    // If true, don't delete large ZIP file created for test.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    33
    static final boolean debug = System.getProperty("debug") != null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    34
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    35
    //static final int DATA_LEN = 1024 * 1024;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    36
    static final int DATA_LEN = 80 * 1024;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    37
    static final int DATA_SIZE = 8;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    38
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    39
    static long fileSize = 6L * 1024L * 1024L * 1024L; // 6GB
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    40
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    41
    static boolean userFile = false;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    42
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    43
    static byte[] data;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    44
    static File largeFile;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    45
    static String lastEntryName;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    46
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    47
    /* args can be empty, in which case check a 3 GB file which is created for
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    48
     * this test (and then deleted).  Or it can be a number, in which case
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    49
     * that designates the size of the file that's created for this test (and
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    50
     * then deleted).  Or it can be the name of a file to use for the test, in
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    51
     * which case it is *not* deleted.  Note that in this last case, the data
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    52
     * comparison might fail.
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    53
     */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    54
    static void realMain (String[] args) throws Throwable {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    55
        if (args.length > 0) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    56
            try {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    57
                fileSize = Long.parseLong(args[0]);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    58
                System.out.println("Testing with file of size " + fileSize);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    59
            } catch (NumberFormatException ex) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    60
                largeFile = new File(args[0]);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    61
                if (!largeFile.exists()) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    62
                    throw new Exception("Specified file " + args[0] + " does not exist");
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    63
                }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    64
                userFile = true;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    65
                System.out.println("Testing with user-provided file " + largeFile);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    66
            }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    67
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    68
        File testDir = null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    69
        if (largeFile == null) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    70
            testDir = new File(System.getProperty("test.scratch", "."),
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    71
                                    "LargeZip");
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    72
            if (testDir.exists()) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    73
                if (!testDir.delete()) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    74
                    throw new Exception("Cannot delete already-existing test directory");
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    75
                }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    76
            }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    77
            check(!testDir.exists() && testDir.mkdirs());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    78
            largeFile = new File(testDir, "largezip.zip");
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    79
            createLargeZip();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    80
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    81
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    82
        readLargeZip1();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    83
        readLargeZip2();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    84
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    85
        if (!userFile && !debug) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    86
            check(largeFile.delete());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    87
            check(testDir.delete());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    88
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    89
    }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    90
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    91
    static void createLargeZip() throws Throwable {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    92
        int iterations = DATA_LEN / DATA_SIZE;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    93
        ByteBuffer bb = ByteBuffer.allocate(DATA_SIZE);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    94
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    95
        for (int i = 0; i < iterations; i++) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    96
            bb.putDouble(0, Math.random());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    97
            baos.write(bb.array(), 0, DATA_SIZE);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    98
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
    99
        data = baos.toByteArray();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   100
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   101
        ZipOutputStream zos = new ZipOutputStream(
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   102
            new BufferedOutputStream(new FileOutputStream(largeFile)));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   103
        long length = 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   104
        while (length < fileSize) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   105
            ZipEntry ze = new ZipEntry("entry-" + length);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   106
            lastEntryName = ze.getName();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   107
            zos.putNextEntry(ze);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   108
            zos.write(data, 0, data.length);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   109
            zos.closeEntry();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   110
            length = largeFile.length();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   111
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   112
        System.out.println("Last entry written is " + lastEntryName);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   113
        zos.close();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   114
    }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   115
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   116
    static void readLargeZip1() throws Throwable {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   117
        ZipFile zipFile = new ZipFile(largeFile);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   118
        ZipEntry entry = null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   119
        String entryName = null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   120
        int count = 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   121
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   122
        while (entries.hasMoreElements()) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   123
            entry = entries.nextElement();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   124
            entryName = entry.getName();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   125
            count++;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   126
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   127
        System.out.println("Number of entries read: " + count);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   128
        System.out.println("Last entry read is " + entryName);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   129
        check(!entry.isDirectory());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   130
        if (check(entryName.equals(lastEntryName))) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   131
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   132
            InputStream is = zipFile.getInputStream(entry);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   133
            byte buf[] = new byte[4096];
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   134
            int len;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   135
            while ((len = is.read(buf)) >= 0) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   136
                baos.write(buf, 0, len);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   137
            }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   138
            baos.close();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   139
            is.close();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   140
            check(Arrays.equals(data, baos.toByteArray()));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   141
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   142
    }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   143
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   144
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   145
    static void readLargeZip2() throws Throwable {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   146
        ZipInputStream zis = new ZipInputStream(
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   147
            new BufferedInputStream(new FileInputStream(largeFile)));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   148
        ZipEntry entry = null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   149
        String entryName = null;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   150
        int count = 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   151
        while ((entry = zis.getNextEntry()) != null) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   152
            entryName = entry.getName();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   153
            if (entryName.equals(lastEntryName)) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   154
                break;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   155
            }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   156
            count++;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   157
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   158
        System.out.println("Number of entries read: " + count);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   159
        System.out.println("Last entry read is " + entryName);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   160
        check(!entry.isDirectory());
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   161
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   162
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   163
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   164
        byte buf[] = new byte[4096];
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   165
        int len;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   166
        while ((len = zis.read(buf)) >= 0) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   167
            baos.write(buf, 0, len);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   168
        }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   169
        baos.close();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   170
        check(Arrays.equals(data, baos.toByteArray()));
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   171
        check(zis.getNextEntry() == null);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   172
        zis.close();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   173
    }
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   174
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   175
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   176
    //--------------------- Infrastructure ---------------------------
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   177
    static volatile int passed = 0, failed = 0;
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   178
    static void pass() {passed++;}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   179
    static void pass(String msg) {System.out.println(msg); passed++;}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   180
    static void fail() {failed++; Thread.dumpStack();}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   181
    static void fail(String msg) {System.out.println(msg); fail();}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   182
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   183
    static void unexpected(Throwable t, String msg) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   184
        System.out.println(msg); failed++; t.printStackTrace();}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   185
    static boolean check(boolean cond) {if (cond) pass(); else fail(); return cond;}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   186
    static void equal(Object x, Object y) {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   187
        if (x == null ? y == null : x.equals(y)) pass();
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   188
        else fail(x + " not equal to " + y);}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   189
    public static void main(String[] args) throws Throwable {
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   190
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   191
        System.out.println("\nPassed = " + passed + " failed = " + failed);
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   192
        if (failed > 0) throw new AssertionError("Some tests failed");}
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents:
diff changeset
   193
}