src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipInfo.java
author clanger
Fri, 17 May 2019 09:00:39 +0100
changeset 54920 6a6935abebe8
parent 53043 fd2e8f941ded
permissions -rw-r--r--
8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031 Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
     1
/*
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
     2
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
     4
 *
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    10
 *
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    15
 * accompanied this code).
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    16
 *
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    20
 *
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    23
 * questions.
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    24
 */
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    25
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    26
package jdk.nio.zipfs;
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    27
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    28
import java.nio.file.Paths;
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    29
import java.util.Collections;
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    30
import java.util.Map;
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
    31
import java.util.zip.ZipException;
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 47216
diff changeset
    32
23925
0d5f2d863262 8038500: (zipfs) Upgrade ZIP provider to be a supported provider
sherman
parents: 23010
diff changeset
    33
import static jdk.nio.zipfs.ZipConstants.*;
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 47216
diff changeset
    34
import static jdk.nio.zipfs.ZipUtils.dosToJavaTime;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 47216
diff changeset
    35
import static jdk.nio.zipfs.ZipUtils.unixToJavaTime;
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 47216
diff changeset
    36
import static jdk.nio.zipfs.ZipUtils.winToJavaTime;
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    37
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    38
/**
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    39
 * Print all loc and cen headers of the ZIP file
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    40
 *
53043
fd2e8f941ded 8215472: (zipfs) Cleanups in implementation classes of jdk.zipfs and tests
clanger
parents: 47216
diff changeset
    41
 * @author Xueming Shen
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    42
 */
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    43
public class ZipInfo {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    44
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    45
    public static void main(String[] args) throws Throwable {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    46
        if (args.length < 1) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    47
            print("Usage: java ZipInfo zfname");
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    48
        } else {
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    49
            Map<String, ?> env = Collections.emptyMap();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    50
            ZipFileSystem zfs = (ZipFileSystem)(new ZipFileSystemProvider()
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    51
                                    .newFileSystem(Paths.get(args[0]), env));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    52
            byte[] cen = zfs.cen;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    53
            if (cen == null) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    54
                print("zip file is empty%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    55
                return;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    56
            }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    57
            int    pos = 0;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    58
            byte[] buf = new byte[1024];
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    59
            int    no = 1;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    60
            while (pos + CENHDR < cen.length) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    61
                print("----------------#%d--------------------%n", no++);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    62
                printCEN(cen, pos);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    63
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    64
                // use size CENHDR as the extra bytes to read, just in case the
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    65
                // loc.extra is bigger than the cen.extra, try to avoid to read
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    66
                // twice
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    67
                long len = LOCHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENHDR;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    68
                if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
    69
                    throw new ZipException("read loc header failed");
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    70
                if (LOCEXT(buf) > CENEXT(cen, pos) + CENHDR) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    71
                    // have to read the second time;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    72
                    len = LOCHDR + LOCNAM(buf) + LOCEXT(buf);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    73
                    if (zfs.readFullyAt(buf, 0, len, locoff(cen, pos)) != len)
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
    74
                        throw new ZipException("read loc header failed");
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    75
                }
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    76
                printLOC(buf);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    77
                pos += CENHDR + CENNAM(cen, pos) + CENEXT(cen, pos) + CENCOM(cen, pos);
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    78
            }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    79
            zfs.close();
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    80
        }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    81
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    82
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
    83
    private static void print(String fmt, Object... objs) {
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    84
        System.out.printf(fmt, objs);
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    85
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
    86
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
    87
    private static void printLOC(byte[] loc) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    88
        print("%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    89
        print("[Local File Header]%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    90
        print("    Signature   :   %#010x%n", LOCSIG(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    91
        if (LOCSIG(loc) != LOCSIG) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    92
           print("    Wrong signature!");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    93
           return;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    94
        }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    95
        print("    Version     :       %#6x    [%d.%d]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    96
                  LOCVER(loc), LOCVER(loc) / 10, LOCVER(loc) % 10);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    97
        print("    Flag        :       %#6x%n", LOCFLG(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    98
        print("    Method      :       %#6x%n", LOCHOW(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
    99
        print("    LastMTime   :   %#10x    [%tc]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   100
              LOCTIM(loc), dosToJavaTime(LOCTIM(loc)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   101
        print("    CRC         :   %#10x%n", LOCCRC(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   102
        print("    CSize       :   %#10x%n", LOCSIZ(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   103
        print("    Size        :   %#10x%n", LOCLEN(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   104
        print("    NameLength  :       %#6x    [%s]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   105
                  LOCNAM(loc), new String(loc, LOCHDR, LOCNAM(loc)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   106
        print("    ExtraLength :       %#6x%n", LOCEXT(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   107
        if (LOCEXT(loc) != 0)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   108
            printExtra(loc, LOCHDR + LOCNAM(loc), LOCEXT(loc));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   109
    }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   110
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
   111
    private static void printCEN(byte[] cen, int off) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   112
        print("[Central Directory Header]%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   113
        print("    Signature   :   %#010x%n", CENSIG(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   114
        if (CENSIG(cen, off) != CENSIG) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   115
           print("    Wrong signature!");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   116
           return;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   117
        }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   118
        print("    VerMadeby   :       %#6x    [%d, %d.%d]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   119
              CENVEM(cen, off), (CENVEM(cen, off) >> 8),
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   120
              (CENVEM(cen, off) & 0xff) / 10,
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   121
              (CENVEM(cen, off) & 0xff) % 10);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   122
        print("    VerExtract  :       %#6x    [%d.%d]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   123
              CENVER(cen, off), CENVER(cen, off) / 10, CENVER(cen, off) % 10);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   124
        print("    Flag        :       %#6x%n", CENFLG(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   125
        print("    Method      :       %#6x%n", CENHOW(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   126
        print("    LastMTime   :   %#10x    [%tc]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   127
              CENTIM(cen, off), dosToJavaTime(CENTIM(cen, off)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   128
        print("    CRC         :   %#10x%n", CENCRC(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   129
        print("    CSize       :   %#10x%n", CENSIZ(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   130
        print("    Size        :   %#10x%n", CENLEN(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   131
        print("    NameLen     :       %#6x    [%s]%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   132
              CENNAM(cen, off), new String(cen, off + CENHDR, CENNAM(cen, off)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   133
        print("    ExtraLen    :       %#6x%n", CENEXT(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   134
        if (CENEXT(cen, off) != 0)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   135
            printExtra(cen, off + CENHDR + CENNAM(cen, off), CENEXT(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   136
        print("    CommentLen  :       %#6x%n", CENCOM(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   137
        print("    DiskStart   :       %#6x%n", CENDSK(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   138
        print("    Attrs       :       %#6x%n", CENATT(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   139
        print("    AttrsEx     :   %#10x%n", CENATX(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   140
        print("    LocOff      :   %#10x%n", CENOFF(cen, off));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   141
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   142
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   143
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
   144
    private static long locoff(byte[] cen, int pos) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   145
        long locoff = CENOFF(cen, pos);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   146
        if (locoff == ZIP64_MINVAL) {    //ZIP64
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   147
            int off = pos + CENHDR + CENNAM(cen, pos);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   148
            int end = off + CENEXT(cen, pos);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   149
            while (off + 4 < end) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   150
                int tag = SH(cen, off);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   151
                int sz = SH(cen, off + 2);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   152
                if (tag != EXTID_ZIP64) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   153
                    off += 4 + sz;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   154
                    continue;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   155
                }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   156
                off += 4;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   157
                if (CENLEN(cen, pos) == ZIP64_MINVAL)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   158
                    off += 8;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   159
                if (CENSIZ(cen, pos) == ZIP64_MINVAL)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   160
                    off += 8;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   161
                return LL(cen, off);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   162
            }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   163
            // should never be here
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   164
        }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   165
        return locoff;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   166
    }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   167
54920
6a6935abebe8 8222276: (zipfs) Refactoring and cleanups to prepare for JDK-8213031
clanger
parents: 53043
diff changeset
   168
    private static void printExtra(byte[] extra, int off, int len) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   169
        int end = off + len;
7531
77870839c857 6989148: (fs) zip provider should be available "out of the box"
sherman
parents: 7189
diff changeset
   170
        while (off + 4 <= end) {
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   171
            int tag = SH(extra, off);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   172
            int sz = SH(extra, off + 2);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   173
            print("        [tag=0x%04x, sz=%d, data= ", tag, sz);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   174
            if (off + sz > end) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   175
                print("    Error: Invalid extra data, beyond extra length");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   176
                break;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   177
            }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   178
            off += 4;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   179
            for (int i = 0; i < sz; i++)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   180
                print("%02x ", extra[off + i]);
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   181
            print("]%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   182
            switch (tag) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   183
            case EXTID_ZIP64 :
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   184
                print("         ->ZIP64: ");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   185
                int pos = off;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   186
                while (pos + 8 <= off + sz) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   187
                    print(" *0x%x ", LL(extra, pos));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   188
                    pos += 8;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   189
                }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   190
                print("%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   191
                break;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   192
            case EXTID_NTFS:
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   193
                print("         ->PKWare NTFS%n");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   194
                // 4 bytes reserved
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   195
                if (SH(extra, off + 4) !=  0x0001 || SH(extra, off + 6) !=  24)
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   196
                    print("    Error: Invalid NTFS sub-tag or subsz");
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   197
                print("            mtime:%tc%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   198
                      winToJavaTime(LL(extra, off + 8)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   199
                print("            atime:%tc%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   200
                      winToJavaTime(LL(extra, off + 16)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   201
                print("            ctime:%tc%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   202
                      winToJavaTime(LL(extra, off + 24)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   203
                break;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   204
            case EXTID_EXTT:
17910
82d10099a8a6 4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents: 14342
diff changeset
   205
                print("         ->Info-ZIP Extended Timestamp: flag=%x%n",extra[off]);
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   206
                pos = off + 1 ;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   207
                while (pos + 4 <= off + sz) {
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   208
                    print("            *%tc%n",
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   209
                          unixToJavaTime(LG(extra, pos)));
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   210
                    pos += 4;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   211
                }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   212
                break;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   213
            default:
17910
82d10099a8a6 4759491: method ZipEntry.setTime(long) works incorrectly
sherman
parents: 14342
diff changeset
   214
                print("         ->[tag=%x, size=%d]%n", tag, sz);
7189
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   215
            }
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   216
            off += sz;
5749df30059b 6994145: (zipfs) README should be updated
sherman
parents: 6699
diff changeset
   217
        }
6699
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   218
    }
d8229570529d 6990846: Demo: NIO.2 filesystem provider for zip/jar archives
sherman
parents:
diff changeset
   219
}