src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipUtils.java
changeset 57665 bf325b739c8a
parent 53043 fd2e8f941ded
equal deleted inserted replaced
57664:1d2ea8db7083 57665:bf325b739c8a
     1 /*
     1 /*
     2  * Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    25 
    25 
    26 package jdk.nio.zipfs;
    26 package jdk.nio.zipfs;
    27 
    27 
    28 import java.io.IOException;
    28 import java.io.IOException;
    29 import java.io.OutputStream;
    29 import java.io.OutputStream;
       
    30 import java.nio.file.attribute.PosixFilePermission;
    30 import java.time.DateTimeException;
    31 import java.time.DateTimeException;
    31 import java.time.Instant;
    32 import java.time.Instant;
    32 import java.time.LocalDateTime;
    33 import java.time.LocalDateTime;
    33 import java.time.ZoneId;
    34 import java.time.ZoneId;
    34 import java.util.Arrays;
    35 import java.util.Arrays;
    35 import java.util.Date;
    36 import java.util.Date;
       
    37 import java.util.Set;
    36 import java.util.concurrent.TimeUnit;
    38 import java.util.concurrent.TimeUnit;
    37 import java.util.regex.PatternSyntaxException;
    39 import java.util.regex.PatternSyntaxException;
    38 
    40 
    39 /**
    41 /**
    40  * @author Xueming Shen
    42  * @author Xueming Shen
    41  */
    43  */
    42 class ZipUtils {
    44 class ZipUtils {
       
    45 
       
    46     /**
       
    47      * The bit flag used to specify read permission by the owner.
       
    48      */
       
    49     static final int POSIX_USER_READ = 0400;
       
    50 
       
    51     /**
       
    52      * The bit flag used to specify write permission by the owner.
       
    53      */
       
    54     static final int POSIX_USER_WRITE = 0200;
       
    55 
       
    56     /**
       
    57      * The bit flag used to specify execute permission by the owner.
       
    58      */
       
    59     static final int POSIX_USER_EXECUTE = 0100;
       
    60 
       
    61     /**
       
    62      * The bit flag used to specify read permission by the group.
       
    63      */
       
    64     static final int POSIX_GROUP_READ = 040;
       
    65 
       
    66     /**
       
    67      * The bit flag used to specify write permission by the group.
       
    68      */
       
    69     static final int POSIX_GROUP_WRITE = 020;
       
    70 
       
    71     /**
       
    72      * The bit flag used to specify execute permission by the group.
       
    73      */
       
    74     static final int POSIX_GROUP_EXECUTE = 010;
       
    75 
       
    76     /**
       
    77      * The bit flag used to specify read permission by others.
       
    78      */
       
    79     static final int POSIX_OTHER_READ = 04;
       
    80 
       
    81     /**
       
    82      * The bit flag used to specify write permission by others.
       
    83      */
       
    84     static final int POSIX_OTHER_WRITE = 02;
       
    85 
       
    86     /**
       
    87      * The bit flag used to specify execute permission by others.
       
    88      */
       
    89     static final int POSIX_OTHER_EXECUTE = 01;
       
    90 
       
    91     /**
       
    92      * Convert a {@link PosixFilePermission} object into the appropriate bit
       
    93      * flag.
       
    94      *
       
    95      * @param perm The {@link PosixFilePermission} object.
       
    96      * @return The bit flag as int.
       
    97      */
       
    98     static int permToFlag(PosixFilePermission perm) {
       
    99         switch(perm) {
       
   100         case OWNER_READ:
       
   101             return POSIX_USER_READ;
       
   102         case OWNER_WRITE:
       
   103             return POSIX_USER_WRITE;
       
   104         case OWNER_EXECUTE:
       
   105             return POSIX_USER_EXECUTE;
       
   106         case GROUP_READ:
       
   107             return POSIX_GROUP_READ;
       
   108         case GROUP_WRITE:
       
   109             return POSIX_GROUP_WRITE;
       
   110         case GROUP_EXECUTE:
       
   111             return POSIX_GROUP_EXECUTE;
       
   112         case OTHERS_READ:
       
   113             return POSIX_OTHER_READ;
       
   114         case OTHERS_WRITE:
       
   115             return POSIX_OTHER_WRITE;
       
   116         case OTHERS_EXECUTE:
       
   117             return POSIX_OTHER_EXECUTE;
       
   118         default:
       
   119             return 0;
       
   120         }
       
   121     }
       
   122 
       
   123     /**
       
   124      * Converts a set of {@link PosixFilePermission}s into an int value where
       
   125      * the according bits are set.
       
   126      *
       
   127      * @param perms A Set of {@link PosixFilePermission} objects.
       
   128      *
       
   129      * @return A bit mask representing the input Set.
       
   130      */
       
   131     static int permsToFlags(Set<PosixFilePermission> perms) {
       
   132         if (perms == null) {
       
   133             return -1;
       
   134         }
       
   135         int flags = 0;
       
   136         for (PosixFilePermission perm : perms) {
       
   137             flags |= permToFlag(perm);
       
   138         }
       
   139         return flags;
       
   140     }
    43 
   141 
    44     /*
   142     /*
    45      * Writes a 16-bit short to the output stream in little-endian byte order.
   143      * Writes a 16-bit short to the output stream in little-endian byte order.
    46      */
   144      */
    47     public static void writeShort(OutputStream os, int v) throws IOException {
   145     public static void writeShort(OutputStream os, int v) throws IOException {