< prev index next >

src/java.base/windows/classes/sun/nio/fs/WindowsFileStore.java

Print this page


   1 /*
   2  * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


 108     int volumeType() {
 109         return volType;
 110     }
 111 
 112     @Override
 113     public String name() {
 114         return volInfo.volumeName();   // "SYSTEM", "DVD-RW", ...
 115     }
 116 
 117     @Override
 118     public String type() {
 119         return volInfo.fileSystemName();  // "FAT", "NTFS", ...
 120     }
 121 
 122     @Override
 123     public boolean isReadOnly() {
 124         return ((volInfo.flags() & FILE_READ_ONLY_VOLUME) != 0);
 125     }
 126 
 127     // read the free space info
 128     private DiskFreeSpace readDiskFreeSpace() throws IOException {
 129         try {
 130             return GetDiskFreeSpaceEx(root);
 131         } catch (WindowsException x) {
 132             x.rethrowAsIOException(root);
 133             return null;
 134         }
 135     }
 136 









 137     @Override
 138     public long getTotalSpace() throws IOException {
 139         return readDiskFreeSpace().totalNumberOfBytes();
 140     }
 141 
 142     @Override
 143     public long getUsableSpace() throws IOException {
 144         return readDiskFreeSpace().freeBytesAvailable();




 145     }
 146 
 147     @Override
 148     public long getUnallocatedSpace() throws IOException {
 149         return readDiskFreeSpace().freeBytesAvailable();
 150     }
 151 
 152     @Override
 153     public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) {
 154         if (type == null)
 155             throw new NullPointerException();
 156         return (V) null;
 157     }
 158 
 159     @Override
 160     public Object getAttribute(String attribute) throws IOException {
 161         // standard
 162         if (attribute.equals("totalSpace"))
 163             return getTotalSpace();
 164         if (attribute.equals("usableSpace"))
 165             return getUsableSpace();
 166         if (attribute.equals("unallocatedSpace"))
 167             return getUnallocatedSpace();


 168         // windows specific for testing purposes
 169         if (attribute.equals("volume:vsn"))
 170             return volInfo.volumeSerialNumber();
 171         if (attribute.equals("volume:isRemovable"))
 172             return volType == DRIVE_REMOVABLE;
 173         if (attribute.equals("volume:isCdrom"))
 174             return volType == DRIVE_CDROM;
 175         throw new UnsupportedOperationException("'" + attribute + "' not recognized");
 176     }
 177 
 178     @Override
 179     public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
 180         if (type == null)
 181             throw new NullPointerException();
 182         if (type == BasicFileAttributeView.class || type == DosFileAttributeView.class)
 183             return true;
 184         if (type == AclFileAttributeView.class || type == FileOwnerAttributeView.class)
 185             return ((volInfo.flags() & FILE_PERSISTENT_ACLS) != 0);
 186         if (type == UserDefinedFileAttributeView.class)
 187             return ((volInfo.flags() & FILE_NAMED_STREAMS) != 0);


   1 /*
   2  * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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


 108     int volumeType() {
 109         return volType;
 110     }
 111 
 112     @Override
 113     public String name() {
 114         return volInfo.volumeName();   // "SYSTEM", "DVD-RW", ...
 115     }
 116 
 117     @Override
 118     public String type() {
 119         return volInfo.fileSystemName();  // "FAT", "NTFS", ...
 120     }
 121 
 122     @Override
 123     public boolean isReadOnly() {
 124         return ((volInfo.flags() & FILE_READ_ONLY_VOLUME) != 0);
 125     }
 126 
 127     // read the free space info
 128     private DiskFreeSpace readDiskFreeSpaceEx() throws IOException {
 129         try {
 130             return GetDiskFreeSpaceEx(root);
 131         } catch (WindowsException x) {
 132             x.rethrowAsIOException(root);
 133             return null;
 134         }
 135     }
 136 
 137     private DiskFreeSpace readDiskFreeSpace() throws IOException {
 138         try {
 139             return GetDiskFreeSpace(root);
 140         } catch (WindowsException x) {
 141             x.rethrowAsIOException(root);
 142             return null;
 143         }
 144     }
 145 
 146     @Override
 147     public long getTotalSpace() throws IOException {
 148         return readDiskFreeSpaceEx().totalNumberOfBytes();
 149     }
 150 
 151     @Override
 152     public long getUsableSpace() throws IOException {
 153         return readDiskFreeSpaceEx().freeBytesAvailable();
 154     }
 155 
 156     public long getBlockSize() throws IOException {
 157         return readDiskFreeSpace().bytesPerSector();
 158     }
 159 
 160     @Override
 161     public long getUnallocatedSpace() throws IOException {
 162         return readDiskFreeSpaceEx().freeBytesAvailable();
 163     }
 164 
 165     @Override
 166     public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) {
 167         if (type == null)
 168             throw new NullPointerException();
 169         return (V) null;
 170     }
 171 
 172     @Override
 173     public Object getAttribute(String attribute) throws IOException {
 174         // standard
 175         if (attribute.equals("totalSpace"))
 176             return getTotalSpace();
 177         if (attribute.equals("usableSpace"))
 178             return getUsableSpace();
 179         if (attribute.equals("unallocatedSpace"))
 180             return getUnallocatedSpace();
 181         if (attribute.equals("bytesPerSector"))
 182             return getBlockSize();
 183         // windows specific for testing purposes
 184         if (attribute.equals("volume:vsn"))
 185             return volInfo.volumeSerialNumber();
 186         if (attribute.equals("volume:isRemovable"))
 187             return volType == DRIVE_REMOVABLE;
 188         if (attribute.equals("volume:isCdrom"))
 189             return volType == DRIVE_CDROM;
 190         throw new UnsupportedOperationException("'" + attribute + "' not recognized");
 191     }
 192 
 193     @Override
 194     public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
 195         if (type == null)
 196             throw new NullPointerException();
 197         if (type == BasicFileAttributeView.class || type == DosFileAttributeView.class)
 198             return true;
 199         if (type == AclFileAttributeView.class || type == FileOwnerAttributeView.class)
 200             return ((volInfo.flags() & FILE_PERSISTENT_ACLS) != 0);
 201         if (type == UserDefinedFileAttributeView.class)
 202             return ((volInfo.flags() & FILE_NAMED_STREAMS) != 0);


< prev index next >