--- old/src/solaris/classes/sun/nio/fs/UnixFileStore.java Wed Jan 26 14:13:11 2011 +++ new/src/solaris/classes/sun/nio/fs/UnixFileStore.java Wed Jan 26 14:13:10 2011 @@ -102,29 +102,51 @@ public boolean isReadOnly() { return entry.isReadOnly(); } + + // uses statvfs to read the file system information + private UnixFileStoreAttributes readAttributes() throws IOException { + try { + return UnixFileStoreAttributes.get(file); + } catch (UnixException x) { + x.rethrowAsIOException(file); + return null; // keep compile happy + } + } @Override + public long getTotalSpace() throws IOException { + UnixFileStoreAttributes attrs = readAttributes(); + return attrs.blockSize() * attrs.totalBlocks(); + } + + @Override + public long getUsableSpace() throws IOException { + UnixFileStoreAttributes attrs = readAttributes(); + return attrs.blockSize() * attrs.availableBlocks(); + } + + @Override + public long getUnallocatedSpace() throws IOException { + UnixFileStoreAttributes attrs = readAttributes(); + return attrs.blockSize() * attrs.freeBlocks(); + } + + @Override @SuppressWarnings("unchecked") public V getFileStoreAttributeView(Class view) { - if (view == null) - throw new NullPointerException(); - if (view == FileStoreSpaceAttributeView.class) - return (V) new UnixFileStoreSpaceAttributeView(this); + Objects.nonNull(view); return (V) null; } @Override public Object getAttribute(String attribute) throws IOException { - if (attribute.equals("space:totalSpace")) - return new UnixFileStoreSpaceAttributeView(this) - .readAttributes().totalSpace(); - if (attribute.equals("space:usableSpace")) - return new UnixFileStoreSpaceAttributeView(this) - .readAttributes().usableSpace(); - if (attribute.equals("space:unallocatedSpace")) - return new UnixFileStoreSpaceAttributeView(this) - .readAttributes().unallocatedSpace(); + if (attribute.equals("totalSpace")) + return getTotalSpace(); + if (attribute.equals("usableSpace")) + return getUsableSpace(); + if (attribute.equals("unallocatedSpace")) + return getUnallocatedSpace(); throw new UnsupportedOperationException("'" + attribute + "' not recognized"); } @@ -181,50 +203,6 @@ return sb.toString(); } - private static class UnixFileStoreSpaceAttributeView - implements FileStoreSpaceAttributeView - { - private final UnixFileStore fs; - - UnixFileStoreSpaceAttributeView(UnixFileStore fs) { - this.fs = fs; - } - - @Override - public String name() { - return "space"; - } - - @Override - public FileStoreSpaceAttributes readAttributes() - throws IOException - { - UnixPath file = fs.file(); - final UnixFileStoreAttributes attrs; - try { - attrs = UnixFileStoreAttributes.get(file); - } catch (UnixException x) { - x.rethrowAsIOException(file); - return null; // keep compile happy - } - - return new FileStoreSpaceAttributes() { - @Override - public long totalSpace() { - return attrs.blockSize() * attrs.totalBlocks(); - } - @Override - public long usableSpace() { - return attrs.blockSize() * attrs.availableBlocks(); - } - @Override - public long unallocatedSpace() { - return attrs.blockSize() * attrs.freeBlocks(); - } - }; - } - } - // -- fstypes.properties -- private static final Object loadLock = new Object(); @@ -277,11 +255,8 @@ String fstypes = System.getProperty("java.home") + "/lib/fstypes.properties"; Path file = Paths.get(fstypes); try { - ReadableByteChannel rbc = file.newByteChannel(); - try { + try (ReadableByteChannel rbc = Files.newByteChannel(file)) { result.load(Channels.newReader(rbc, "UTF-8")); - } finally { - rbc.close(); } } catch (IOException x) { }