< prev index next >

src/java.base/windows/classes/java/io/WinNTFileSystem.java

Print this page
rev 17391 : 8182710: File.listRoots() always returns the root of CD drive
Summary: Include only logical drives with an extant filesystem location
Reviewed-by: XXX
rev 16471 : 8153250: java.io.File does not handle Windows paths of the form "D:" (no path) correctly
Summary: When resolving a child to a parent, do not insert a file separator for Windows directory-relative paths
Reviewed-by: rriggs
rev 16362 : 8148023: File.createTempFile is not adhering to the contract regarding file name lengths
Summary: Truncate the prefix, suffix, random characters per the specification
Reviewed-by: rriggs
rev 14359 : 8155775: Re-examine naming of privileged methods to access System properties
Reviewed-by: mullan
rev 14265 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs, chegar, weijun
rev 12301 : 8077242: (str) Optimize AbstractStringBuilder.append(CharSequence, int, int) for String argument
Reviewed-by: martin
rev 10444 : 8054834: Modular Source Code
Reviewed-by: alanb, chegar, ihse, mduigou
Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com


  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.io;
  27 
  28 import java.io.File;
  29 import java.nio.file.Path;

  30 import java.util.Locale;
  31 import java.util.Properties;
  32 import sun.security.action.GetPropertyAction;
  33 
  34 /**
  35  * Unicode-aware FileSystem for Windows NT/2000.
  36  *
  37  * @author Konstantin Kladko
  38  * @since 1.4
  39  */
  40 class WinNTFileSystem extends FileSystem {
  41 
  42     private final char slash;
  43     private final char altSlash;
  44     private final char semicolon;
  45 
  46     public WinNTFileSystem() {
  47         Properties props = GetPropertyAction.privilegedGetProperties();
  48         slash = props.getProperty("file.separator").charAt(0);
  49         semicolon = props.getProperty("path.separator").charAt(0);


 570 
 571     @Override
 572     public boolean rename(File f1, File f2) {
 573         // Keep canonicalization caches in sync after file deletion
 574         // and renaming operations. Could be more clever than this
 575         // (i.e., only remove/update affected entries) but probably
 576         // not worth it since these entries expire after 30 seconds
 577         // anyway.
 578         cache.clear();
 579         prefixCache.clear();
 580         return rename0(f1, f2);
 581     }
 582 
 583     private native boolean rename0(File f1, File f2);
 584 
 585     /* -- Filesystem interface -- */
 586 
 587     @Override
 588     public File[] listRoots() {
 589         int ds = listRoots0();
 590         int n = 0;

 591         for (int i = 0; i < 26; i++) {
 592             if (((ds >> i) & 1) != 0) {
 593                 if (!access((char)('A' + i) + ":" + slash))
 594                     ds &= ~(1 << i);
 595                 else
 596                     n++;
 597             }
 598         }
 599         File[] fs = new File[n];
 600         int j = 0;
 601         char slash = this.slash;
 602         for (int i = 0; i < 26; i++) {
 603             if (((ds >> i) & 1) != 0)
 604                 fs[j++] = new File((char)('A' + i) + ":" + slash);
 605         }
 606         return fs;
 607     }
 608 
 609     private static native int listRoots0();
 610 
 611     private boolean access(String path) {
 612         try {
 613             SecurityManager security = System.getSecurityManager();
 614             if (security != null) security.checkRead(path);
 615             return true;
 616         } catch (SecurityException x) {
 617             return false;
 618         }
 619     }
 620 
 621     /* -- Disk usage -- */
 622 
 623     @Override
 624     public long getSpace(File f, int t) {
 625         if (f.exists()) {
 626             return getSpace0(f, t);




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.io;
  27 
  28 import java.io.File;
  29 import java.nio.file.Path;
  30 import java.util.ArrayList;
  31 import java.util.Locale;
  32 import java.util.Properties;
  33 import sun.security.action.GetPropertyAction;
  34 
  35 /**
  36  * Unicode-aware FileSystem for Windows NT/2000.
  37  *
  38  * @author Konstantin Kladko
  39  * @since 1.4
  40  */
  41 class WinNTFileSystem extends FileSystem {
  42 
  43     private final char slash;
  44     private final char altSlash;
  45     private final char semicolon;
  46 
  47     public WinNTFileSystem() {
  48         Properties props = GetPropertyAction.privilegedGetProperties();
  49         slash = props.getProperty("file.separator").charAt(0);
  50         semicolon = props.getProperty("path.separator").charAt(0);


 571 
 572     @Override
 573     public boolean rename(File f1, File f2) {
 574         // Keep canonicalization caches in sync after file deletion
 575         // and renaming operations. Could be more clever than this
 576         // (i.e., only remove/update affected entries) but probably
 577         // not worth it since these entries expire after 30 seconds
 578         // anyway.
 579         cache.clear();
 580         prefixCache.clear();
 581         return rename0(f1, f2);
 582     }
 583 
 584     private native boolean rename0(File f1, File f2);
 585 
 586     /* -- Filesystem interface -- */
 587 
 588     @Override
 589     public File[] listRoots() {
 590         int ds = listRoots0();
 591         ArrayList<File> fs = new ArrayList<File>(Integer.bitCount(ds));
 592         char slash = this.slash;
 593         for (int i = 0; i < 26; i++) {
 594             if (((ds >> i) & 1) != 0) {
 595                 File f = new File((char)('A' + i) + ":" + slash);
 596                 if (access(f.getPath()) && f.exists()) {
 597                     fs.add(f);

 598                 }
 599             }






 600         }
 601         return fs.toArray(new File[fs.size()]);
 602     }
 603 
 604     private static native int listRoots0();
 605 
 606     private boolean access(String path) {
 607         try {
 608             SecurityManager security = System.getSecurityManager();
 609             if (security != null) security.checkRead(path);
 610             return true;
 611         } catch (SecurityException x) {
 612             return false;
 613         }
 614     }
 615 
 616     /* -- Disk usage -- */
 617 
 618     @Override
 619     public long getSpace(File f, int t) {
 620         if (f.exists()) {
 621             return getSpace0(f, t);


< prev index next >