1 /*
2 * Copyright (c) 2005, 2012, 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 */
34 import java.io.BufferedReader;
35 import java.io.File;
36 import java.io.FilePermission;
37 import java.io.InputStreamReader;
38 import java.io.IOException;
39 import java.security.Permission;
40 import java.util.ArrayList;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43
44 import static java.lang.System.out;
45
46 public class GetXSpace {
47
48 private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(),
49 new DenyRead() };
50
51 private static final String name = System.getProperty("os.name");
52 private static final String dfFormat;
53 static {
54 if (name.equals("SunOS") || name.equals("Linux")
55 || name.contains("OS X")) {
56 // FileSystem Total Used Available Use% MountedOn
57 dfFormat = "([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s]+)";
58 } else if (name.startsWith("Windows")) {
59 // Drive (MountedOn) Available/Total
60 dfFormat = "([^\\s]+)\\s+\\(([^\\s]+)\\)\\s+(\\d+)\\/(\\d+)\\s+";
61 } else {
62 throw new RuntimeException("unrecognized system:"
63 + " os.name == " + name);
64 }
65 }
66 private static Pattern dfPattern = Pattern.compile(dfFormat);
67
68 private static int fail = 0;
69 private static int pass = 0;
70 private static Throwable first;
71
72 static void pass() {
73 pass++;
74 }
75
|
1 /*
2 * Copyright (c) 2005, 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 */
34 import java.io.BufferedReader;
35 import java.io.File;
36 import java.io.FilePermission;
37 import java.io.InputStreamReader;
38 import java.io.IOException;
39 import java.security.Permission;
40 import java.util.ArrayList;
41 import java.util.regex.Matcher;
42 import java.util.regex.Pattern;
43
44 import static java.lang.System.out;
45
46 public class GetXSpace {
47
48 private static SecurityManager [] sma = { null, new Allow(), new DenyFSA(),
49 new DenyRead() };
50
51 private static final String name = System.getProperty("os.name");
52 private static final String dfFormat;
53 static {
54 if (name.equals("Linux") || name.contains("OS X")) {
55 // FileSystem Total Used Available Use% MountedOn
56 dfFormat = "([^\\s]+)\\s+(\\d+)\\s+\\d+\\s+(\\d+)\\s+\\d+%\\s+([^\\s]+)";
57 } else if (name.startsWith("Windows")) {
58 // Drive (MountedOn) Available/Total
59 dfFormat = "([^\\s]+)\\s+\\(([^\\s]+)\\)\\s+(\\d+)\\/(\\d+)\\s+";
60 } else {
61 throw new RuntimeException("unrecognized system:"
62 + " os.name == " + name);
63 }
64 }
65 private static Pattern dfPattern = Pattern.compile(dfFormat);
66
67 private static int fail = 0;
68 private static int pass = 0;
69 private static Throwable first;
70
71 static void pass() {
72 pass++;
73 }
74
|