src/java.base/windows/classes/sun/nio/fs/WindowsFileAttributes.java
changeset 58341 21a03fa2f6b6
parent 53018 8bf9268df0e2
equal deleted inserted replaced
58340:f4abe950c3b0 58341:21a03fa2f6b6
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 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
   106     private static final short OFFSETOF_FIND_DATA_LASTWRITETIME = 20;
   106     private static final short OFFSETOF_FIND_DATA_LASTWRITETIME = 20;
   107     private static final short OFFSETOF_FIND_DATA_SIZEHIGH = 28;
   107     private static final short OFFSETOF_FIND_DATA_SIZEHIGH = 28;
   108     private static final short OFFSETOF_FIND_DATA_SIZELOW = 32;
   108     private static final short OFFSETOF_FIND_DATA_SIZELOW = 32;
   109     private static final short OFFSETOF_FIND_DATA_RESERVED0 = 36;
   109     private static final short OFFSETOF_FIND_DATA_RESERVED0 = 36;
   110 
   110 
   111     // used to adjust values between Windows and java epoch
   111     // used to adjust values between Windows and java epochs
   112     private static final long WINDOWS_EPOCH_IN_MICROSECONDS = -11644473600000000L;
   112     private static final long WINDOWS_EPOCH_IN_MICROS = -11644473600000000L;
       
   113     private static final long WINDOWS_EPOCH_IN_100NS  = -116444736000000000L;
   113 
   114 
   114     // indicates if accurate metadata is required (interesting on NTFS only)
   115     // indicates if accurate metadata is required (interesting on NTFS only)
   115     private static final boolean ensureAccurateMetadata;
   116     private static final boolean ensureAccurateMetadata;
   116     static {
   117     static {
   117         String propValue = GetPropertyAction.privilegedGetProperty(
   118         String propValue = GetPropertyAction.privilegedGetProperty(
   135     /**
   136     /**
   136      * Convert 64-bit value representing the number of 100-nanosecond intervals
   137      * Convert 64-bit value representing the number of 100-nanosecond intervals
   137      * since January 1, 1601 to a FileTime.
   138      * since January 1, 1601 to a FileTime.
   138      */
   139      */
   139     static FileTime toFileTime(long time) {
   140     static FileTime toFileTime(long time) {
   140         // 100ns -> us
   141         try {
   141         time /= 10L;
   142             long adjusted = Math.addExact(time, WINDOWS_EPOCH_IN_100NS);
   142         // adjust to java epoch
   143             long nanos = Math.multiplyExact(adjusted, 100L);
   143         time += WINDOWS_EPOCH_IN_MICROSECONDS;
   144             return FileTime.from(nanos, TimeUnit.NANOSECONDS);
   144         return FileTime.from(time, TimeUnit.MICROSECONDS);
   145         } catch (ArithmeticException e) {
   145     }
   146             long micros = Math.addExact(time/10L, WINDOWS_EPOCH_IN_MICROS);
   146 
   147             return FileTime.from(micros, TimeUnit.MICROSECONDS);
   147     /**
   148         }
   148      * Convert FileTime to 64-bit value representing the number of 100-nanosecond
   149     }
   149      * intervals since January 1, 1601.
   150 
       
   151     /**
       
   152      * Convert FileTime to 64-bit value representing the number of
       
   153      * 100-nanosecond intervals since January 1, 1601.
   150      */
   154      */
   151     static long toWindowsTime(FileTime time) {
   155     static long toWindowsTime(FileTime time) {
   152         long value = time.to(TimeUnit.MICROSECONDS);
   156         long adjusted = time.to(TimeUnit.NANOSECONDS)/100L;
   153         // adjust to Windows epoch+= 11644473600000000L;
   157         return adjusted - WINDOWS_EPOCH_IN_100NS;
   154         value -= WINDOWS_EPOCH_IN_MICROSECONDS;
       
   155         // us -> 100ns
       
   156         value *= 10L;
       
   157         return value;
       
   158     }
   158     }
   159 
   159 
   160     /**
   160     /**
   161      * Initialize a new instance of this class
   161      * Initialize a new instance of this class
   162      */
   162      */