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
|
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
|