KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > backup > util > OS


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * OS.java
26  *
27  * Created on December 8, 2001, 5:48 PM
28  */

29
30 package com.sun.enterprise.config.backup.util;
31
32 import java.io.*;
33
34 /**
35  *
36  * @author bnevins
37  * @version
38  */

39 public class OS
40 {
41     private OS()
42     {
43     }
44     
45     ///////////////////////////////////////////////////////////////////////////
46

47     public static boolean isWindows()
48     {
49         return File.separatorChar == '\\';
50     }
51     
52     ///////////////////////////////////////////////////////////////////////////
53

54     public static boolean isUNIX()
55     {
56         return File.separatorChar == '/';
57     }
58     
59     ///////////////////////////////////////////////////////////////////////////
60

61     public static boolean isUnix()
62     {
63         // convenience method...
64
return isUNIX();
65     }
66     
67     ///////////////////////////////////////////////////////////////////////////
68

69     public static boolean isSun()
70     {
71         return is("sun");
72     }
73     
74     ///////////////////////////////////////////////////////////////////////////
75

76     public static boolean isLinux()
77     {
78         return is("linux");
79     }
80     
81     ///////////////////////////////////////////////////////////////////////////
82

83     public static boolean isWindowsForSure()
84     {
85         return is("windows") && isWindows();
86     }
87
88     ///////////////////////////////////////////////////////////////////////////
89

90     private static boolean is(String JavaDoc name)
91     {
92         String JavaDoc osname = System.getProperty("os.name");
93         
94         if(osname == null || osname.length() <= 0)
95             return false;
96         
97         // case insensitive compare...
98
osname = osname.toLowerCase();
99         name = name.toLowerCase();
100         
101         if(osname.indexOf(name) >= 0)
102             return true;
103         
104         return false;
105     }
106
107     ///////////////////////////////////////////////////////////////////////////
108

109     /**
110     * @param args the command line arguments
111     */

112     public static void main (String JavaDoc args[])
113     {
114         System.out.println("isUNIX() returned: " + isUNIX());
115         System.out.println("isWindows() returned: " + isWindows());
116         System.out.println("isWindowsForSure() returned: " + isWindowsForSure());
117         System.out.println("isSun() returned: " + isSun());
118         System.out.println("isLinux() returned: " + isLinux());
119     }
120 }
121
Popular Tags