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); | 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 @Override 157 public int getBlockSize() throws IOException { 158 return (int)readDiskFreeSpace().bytesPerSector(); 159 } 160 161 @Override 162 public long getUnallocatedSpace() throws IOException { 163 return readDiskFreeSpaceEx().freeBytesAvailable(); 164 } 165 166 @Override 167 public <V extends FileStoreAttributeView> V getFileStoreAttributeView(Class<V> type) { 168 if (type == null) 169 throw new NullPointerException(); 170 return (V) null; 171 } 172 173 @Override 174 public Object getAttribute(String attribute) throws IOException { 175 // standard 176 if (attribute.equals("totalSpace")) 177 return getTotalSpace(); 178 if (attribute.equals("usableSpace")) 179 return getUsableSpace(); 180 if (attribute.equals("unallocatedSpace")) 181 return getUnallocatedSpace(); 182 if (attribute.equals("bytesPerSector")) 183 return getBlockSize(); 184 // windows specific for testing purposes 185 if (attribute.equals("volume:vsn")) 186 return volInfo.volumeSerialNumber(); 187 if (attribute.equals("volume:isRemovable")) 188 return volType == DRIVE_REMOVABLE; 189 if (attribute.equals("volume:isCdrom")) 190 return volType == DRIVE_CDROM; 191 throw new UnsupportedOperationException("'" + attribute + "' not recognized"); 192 } 193 194 @Override 195 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { 196 if (type == null) 197 throw new NullPointerException(); 198 if (type == BasicFileAttributeView.class || type == DosFileAttributeView.class) 199 return true; 200 if (type == AclFileAttributeView.class || type == FileOwnerAttributeView.class) 201 return ((volInfo.flags() & FILE_PERSISTENT_ACLS) != 0); 202 if (type == UserDefinedFileAttributeView.class) 203 return ((volInfo.flags() & FILE_NAMED_STREAMS) != 0); |