1 /*
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.
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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
98 * Test: Space atributes
99 */
100 File f = file1.toFile();
101 long total = f.getTotalSpace();
102 long free = f.getFreeSpace();
103 long usable = f.getUsableSpace();
104
105 // check values are "close"
106 checkWithin1GB(total, store1.getTotalSpace());
107 checkWithin1GB(free, store1.getUnallocatedSpace());
108 checkWithin1GB(usable, store1.getUsableSpace());
109
110 // get values by name
111 checkWithin1GB(total, (Long)store1.getAttribute("totalSpace"));
112 checkWithin1GB(free, (Long)store1.getAttribute("unallocatedSpace"));
113 checkWithin1GB(usable, (Long)store1.getAttribute("usableSpace"));
114
115 /**
116 * Test: Enumerate all FileStores
117 */
118 if (FileUtils.areAllMountPointsAccessible()) {
119 FileStore prev = null;
120 for (FileStore store: FileSystems.getDefault().getFileStores()) {
121 System.out.format("%s (name=%s type=%s)\n", store, store.name(),
122 store.type());
123
124 // check space attributes are accessible
125 try {
126 store.getTotalSpace();
127 store.getUnallocatedSpace();
128 store.getUsableSpace();
129 } catch (NoSuchFileException nsfe) {
130 // ignore exception as the store could have been
131 // deleted since the iterator was instantiated
132 System.err.format("%s was not found\n", store);
133 } catch (AccessDeniedException ade) {
134 // ignore exception as the lack of ability to access the
135 // store due to lack of file permission or similar does not
136 // reflect whether the space attributes would be accessible
137 // were access to be permitted
138 System.err.format("%s is inaccessible\n", store);
|
1 /*
2 * Copyright (c) 2008, 2020, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
98 * Test: Space atributes
99 */
100 File f = file1.toFile();
101 long total = f.getTotalSpace();
102 long free = f.getFreeSpace();
103 long usable = f.getUsableSpace();
104
105 // check values are "close"
106 checkWithin1GB(total, store1.getTotalSpace());
107 checkWithin1GB(free, store1.getUnallocatedSpace());
108 checkWithin1GB(usable, store1.getUsableSpace());
109
110 // get values by name
111 checkWithin1GB(total, (Long)store1.getAttribute("totalSpace"));
112 checkWithin1GB(free, (Long)store1.getAttribute("unallocatedSpace"));
113 checkWithin1GB(usable, (Long)store1.getAttribute("usableSpace"));
114
115 /**
116 * Test: Enumerate all FileStores
117 */
118 if (FileUtils.areMountPointsAccessibleAndUnique()) {
119 FileStore prev = null;
120 for (FileStore store: FileSystems.getDefault().getFileStores()) {
121 System.out.format("%s (name=%s type=%s)\n", store, store.name(),
122 store.type());
123
124 // check space attributes are accessible
125 try {
126 store.getTotalSpace();
127 store.getUnallocatedSpace();
128 store.getUsableSpace();
129 } catch (NoSuchFileException nsfe) {
130 // ignore exception as the store could have been
131 // deleted since the iterator was instantiated
132 System.err.format("%s was not found\n", store);
133 } catch (AccessDeniedException ade) {
134 // ignore exception as the lack of ability to access the
135 // store due to lack of file permission or similar does not
136 // reflect whether the space attributes would be accessible
137 // were access to be permitted
138 System.err.format("%s is inaccessible\n", store);
|