View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.lang;
18  
19  import java.io.File;
20  
21  /**
22   * <p>Helpers for <code>java.lang.System</code>.</p>
23   * 
24   * <p>If a system property cannot be read due to security restrictions, 
25   * the corresponding field in this class will be set to <code>null</code>
26   * and a message will be written to <code>System.err</code>.</p>
27   *
28   * @author Based on code from Avalon Excalibur
29   * @author Based on code from Lucene
30   * @author Stephen Colebourne
31   * @author <a href="mailto:sdowney@panix.com">Steve Downey</a>
32   * @author Gary Gregory
33   * @author Michael Becke
34   * @author Tetsuya Kaneuchi
35   * @author Rafal Krupinski
36   * @author Jason Gritman
37   * @since 1.0
38   * @version $Id: SystemUtils.java 595798 2007-11-16 20:01:43Z bayard $
39   */
40  public class SystemUtils {
41  
42      /**
43       * The prefix String for all Windows OS.
44       */
45      private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
46      
47      // System property constants
48      //-----------------------------------------------------------------------
49      // These MUST be declared first. Other constants depend on this.
50      
51      /**
52       * The System property key for the user home directory.
53       */
54      private static final String USER_HOME_KEY = "user.home";
55  
56      /**
57       * The System property key for the user directory.
58       */
59      private static final String USER_DIR_KEY = "user.dir";
60      
61      /**
62       * The System property key for the Java IO temporary directory.
63       */
64      private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
65      
66      /**
67       * The System property key for the Java home directory.
68       */
69      private static final String JAVA_HOME_KEY = "java.home";
70      
71      /**
72       * <p>The <code>awt.toolkit</code> System Property.</p>
73       * <p>Holds a class name, on Windows XP this is <code>sun.awt.windows.WToolkit</code>.</p>
74       * <p><b>On platforms without a GUI, this value is <code>null</code>.</b></p>
75       * 
76       * <p>Defaults to <code>null</code> if the runtime does not have
77       * security access to read this property or the property does not exist.</p>
78       * 
79       * <p>
80       * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
81       * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
82       * will be out of sync with that System property.
83       * </p>
84       * 
85       * @since 2.1
86       */
87      public static final String AWT_TOOLKIT = getSystemProperty("awt.toolkit");
88  
89      /**
90       * <p>The <code>file.encoding</code> System Property.</p>
91       * <p>File encoding, such as <code>Cp1252</code>.</p>
92       * 
93       * <p>Defaults to <code>null</code> if the runtime does not have
94       * security access to read this property or the property does not exist.</p>
95       * 
96       * <p>
97       * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
98       * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
99       * will be out of sync with that System property.
100      * </p>
101      * 
102      * @since 2.0
103      * @since Java 1.2
104      */
105     public static final String FILE_ENCODING = getSystemProperty("file.encoding");
106 
107     /**
108      * <p>The <code>file.separator</code> System Property.
109      * File separator (<code>&quot;/&quot;</code> on UNIX).</p>
110      *
111      * <p>Defaults to <code>null</code> if the runtime does not have
112      * security access to read this property or the property does not exist.</p>
113      * 
114      * <p>
115      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
116      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
117      * will be out of sync with that System property.
118      * </p>
119      * 
120      * @since Java 1.1
121      */
122     public static final String FILE_SEPARATOR = getSystemProperty("file.separator");
123 
124     /**
125      * <p>The <code>java.awt.fonts</code> System Property.</p>
126      *
127      * <p>Defaults to <code>null</code> if the runtime does not have
128      * security access to read this property or the property does not exist.</p>
129      * 
130      * <p>
131      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
132      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
133      * will be out of sync with that System property.
134      * </p>
135      * 
136      * @since 2.1
137      */
138     public static final String JAVA_AWT_FONTS = getSystemProperty("java.awt.fonts");
139 
140     /**
141      * <p>The <code>java.awt.graphicsenv</code> System Property.</p>
142      *
143      * <p>Defaults to <code>null</code> if the runtime does not have
144      * security access to read this property or the property does not exist.</p>
145      * 
146      * <p>
147      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
148      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
149      * will be out of sync with that System property.
150      * </p>
151      * 
152      * @since 2.1
153      */
154     public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty("java.awt.graphicsenv");
155 
156     /**
157      * <p>
158      * The <code>java.awt.headless</code> System Property.
159      * The value of this property is the String <code>"true"</code> or <code>"false"</code>. 
160      * </p>
161      *
162      * <p>Defaults to <code>null</code> if the runtime does not have
163      * security access to read this property or the property does not exist.</p>
164      * 
165      * <p>
166      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
167      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
168      * will be out of sync with that System property.
169      * </p>
170      * 
171      * @see #isJavaAwtHeadless()
172      * @since 2.1
173      * @since Java 1.4
174      */
175     public static final String JAVA_AWT_HEADLESS = getSystemProperty("java.awt.headless");
176 
177     /**
178      * <p>The <code>java.awt.printerjob</code> System Property.</p>
179      *
180      * <p>Defaults to <code>null</code> if the runtime does not have
181      * security access to read this property or the property does not exist.</p>
182      * 
183      * <p>
184      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
185      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
186      * will be out of sync with that System property.
187      * </p>
188      * 
189      * @since 2.1
190      */
191     public static final String JAVA_AWT_PRINTERJOB = getSystemProperty("java.awt.printerjob");
192 
193     /**
194      * <p>The <code>java.class.path</code> System Property. Java class path.</p>
195      *
196      * <p>Defaults to <code>null</code> if the runtime does not have
197      * security access to read this property or the property does not exist.</p>
198      * 
199      * <p>
200      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
201      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
202      * will be out of sync with that System property.
203      * </p>
204      * 
205      * @since Java 1.1
206      */
207     public static final String JAVA_CLASS_PATH = getSystemProperty("java.class.path");
208 
209     /**
210      * <p>The <code>java.class.version</code> System Property.
211      * Java class format version number.</p>
212      *
213      * <p>Defaults to <code>null</code> if the runtime does not have
214      * security access to read this property or the property does not exist.</p>
215      * 
216      * <p>
217      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
218      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
219      * will be out of sync with that System property.
220      * </p>
221      * 
222      * @since Java 1.1
223      */
224     public static final String JAVA_CLASS_VERSION = getSystemProperty("java.class.version");
225 
226     /**
227      * <p>The <code>java.compiler</code> System Property. Name of JIT compiler to use.
228      * First in JDK version 1.2. Not used in Sun JDKs after 1.2.</p>
229      *
230      * <p>Defaults to <code>null</code> if the runtime does not have
231      * security access to read this property or the property does not exist.</p>
232      * 
233      * <p>
234      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
235      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
236      * will be out of sync with that System property.
237      * </p>
238      * 
239      * @since Java 1.2. Not used in Sun versions after 1.2.
240      */
241     public static final String JAVA_COMPILER = getSystemProperty("java.compiler");
242 
243     /**
244      * <p>The <code>java.endorsed.dirs</code> System Property. Path of endorsed directory
245      * or directories.</p>
246      *
247      * <p>Defaults to <code>null</code> if the runtime does not have
248      * security access to read this property or the property does not exist.</p>
249      * 
250      * <p>
251      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
252      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
253      * will be out of sync with that System property.
254      * </p>
255      * 
256      * @since Java 1.4
257      */
258     public static final String JAVA_ENDORSED_DIRS = getSystemProperty("java.endorsed.dirs");
259 
260     /**
261      * <p>The <code>java.ext.dirs</code> System Property. Path of extension directory
262      * or directories.</p>
263      *
264      * <p>Defaults to <code>null</code> if the runtime does not have
265      * security access to read this property or the property does not exist.</p>
266      * 
267      * <p>
268      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
269      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
270      * will be out of sync with that System property.
271      * </p>
272      * 
273      * @since Java 1.3
274      */
275     public static final String JAVA_EXT_DIRS = getSystemProperty("java.ext.dirs");
276 
277     /**
278      * <p>The <code>java.home</code> System Property. Java installation directory.</p>
279      *
280      * <p>Defaults to <code>null</code> if the runtime does not have
281      * security access to read this property or the property does not exist.</p>
282      * 
283      * <p>
284      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
285      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
286      * will be out of sync with that System property.
287      * </p>
288      * 
289      * @since Java 1.1
290      */
291     public static final String JAVA_HOME = getSystemProperty(JAVA_HOME_KEY);
292 
293     /**
294      * <p>The <code>java.io.tmpdir</code> System Property. Default temp file path.</p>
295      *
296      * <p>Defaults to <code>null</code> if the runtime does not have
297      * security access to read this property or the property does not exist.</p>
298      * 
299      * <p>
300      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
301      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
302      * will be out of sync with that System property.
303      * </p>
304      * 
305      * @since Java 1.2
306      */
307     public static final String JAVA_IO_TMPDIR = getSystemProperty(JAVA_IO_TMPDIR_KEY);
308 
309     /**
310      * <p>The <code>java.library.path</code> System Property. List of paths to search
311      * when loading libraries.</p>
312      *
313      * <p>Defaults to <code>null</code> if the runtime does not have
314      * security access to read this property or the property does not exist.</p>
315      * 
316      * <p>
317      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
318      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
319      * will be out of sync with that System property.
320      * </p>
321      * 
322      * @since Java 1.2
323      */
324     public static final String JAVA_LIBRARY_PATH = getSystemProperty("java.library.path");
325 
326     /**
327      * <p>The <code>java.runtime.name</code> System Property. Java Runtime Environment
328      * name.</p>
329      *
330      * <p>Defaults to <code>null</code> if the runtime does not have
331      * security access to read this property or the property does not exist.</p>
332      * 
333      * <p>
334      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
335      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
336      * will be out of sync with that System property.
337      * </p>
338      * 
339      * @since 2.0
340      * @since Java 1.3
341      */
342     public static final String JAVA_RUNTIME_NAME = getSystemProperty("java.runtime.name");
343 
344     /**
345      * <p>The <code>java.runtime.version</code> System Property. Java Runtime Environment
346      * version.</p>
347      *
348      * <p>Defaults to <code>null</code> if the runtime does not have
349      * security access to read this property or the property does not exist.</p>
350      * 
351      * <p>
352      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
353      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
354      * will be out of sync with that System property.
355      * </p>
356      * 
357      * @since 2.0
358      * @since Java 1.3
359      */
360     public static final String JAVA_RUNTIME_VERSION = getSystemProperty("java.runtime.version");
361 
362     /**
363      * <p>The <code>java.specification.name</code> System Property. Java Runtime Environment
364      * specification name.</p>
365      *
366      * <p>Defaults to <code>null</code> if the runtime does not have
367      * security access to read this property or the property does not exist.</p>
368      * 
369      * <p>
370      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
371      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
372      * will be out of sync with that System property.
373      * </p>
374      * 
375      * @since Java 1.2
376      */
377     public static final String JAVA_SPECIFICATION_NAME = getSystemProperty("java.specification.name");
378 
379     /**
380      * <p>The <code>java.specification.vendor</code> System Property. Java Runtime Environment
381      * specification vendor.</p>
382      *
383      * <p>Defaults to <code>null</code> if the runtime does not have
384      * security access to read this property or the property does not exist.</p>
385      * 
386      * <p>
387      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
388      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
389      * will be out of sync with that System property.
390      * </p>
391      * 
392      * @since Java 1.2
393      */
394     public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty("java.specification.vendor");
395 
396     /**
397      * <p>The <code>java.specification.version</code> System Property. Java Runtime Environment
398      * specification version.</p>
399      *
400      * <p>Defaults to <code>null</code> if the runtime does not have
401      * security access to read this property or the property does not exist.</p>
402      * 
403      * <p>
404      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
405      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
406      * will be out of sync with that System property.
407      * </p>
408      * 
409      * @since Java 1.3
410      */
411     public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty("java.specification.version");
412 
413     /**
414      * <p>The <code>java.util.prefs.PreferencesFactory</code> System Property. A class name.</p>
415      *
416      * <p>Defaults to <code>null</code> if the runtime does not have
417      * security access to read this property or the property does not exist.</p>
418      * 
419      * <p>
420      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
421      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
422      * will be out of sync with that System property.
423      * </p>
424      * 
425      * @since 2.1
426      * @since Java 1.4
427      */
428     public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = 
429         getSystemProperty("java.util.prefs.PreferencesFactory");
430 
431     /**
432      * <p>The <code>java.vendor</code> System Property. Java vendor-specific string.</p>
433      *
434      * <p>Defaults to <code>null</code> if the runtime does not have
435      * security access to read this property or the property does not exist.</p>
436      * 
437      * <p>
438      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
439      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
440      * will be out of sync with that System property.
441      * </p>
442      * 
443      * @since Java 1.1
444      */
445     public static final String JAVA_VENDOR = getSystemProperty("java.vendor");
446 
447     /**
448      * <p>The <code>java.vendor.url</code> System Property. Java vendor URL.</p>
449      *
450      * <p>Defaults to <code>null</code> if the runtime does not have
451      * security access to read this property or the property does not exist.</p>
452      * 
453      * <p>
454      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
455      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
456      * will be out of sync with that System property.
457      * </p>
458      * 
459      * @since Java 1.1
460     */
461     public static final String JAVA_VENDOR_URL = getSystemProperty("java.vendor.url");
462 
463     /**
464      * <p>The <code>java.version</code> System Property. Java version number.</p>
465      *
466      * <p>Defaults to <code>null</code> if the runtime does not have
467      * security access to read this property or the property does not exist.</p>
468      * 
469      * <p>
470      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
471      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
472      * will be out of sync with that System property.
473      * </p>
474      * 
475      * @since Java 1.1
476      */
477     public static final String JAVA_VERSION = getSystemProperty("java.version");
478 
479     /**
480      * <p>The <code>java.vm.info</code> System Property. Java Virtual Machine implementation
481      * info.</p>
482      *
483      * <p>Defaults to <code>null</code> if the runtime does not have
484      * security access to read this property or the property does not exist.</p>
485      * 
486      * <p>
487      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
488      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
489      * will be out of sync with that System property.
490      * </p>
491      * 
492      * @since 2.0
493      * @since Java 1.2
494      */
495     public static final String JAVA_VM_INFO = getSystemProperty("java.vm.info");
496 
497     /**
498      * <p>The <code>java.vm.name</code> System Property. Java Virtual Machine implementation
499      * name.</p>
500      *
501      * <p>Defaults to <code>null</code> if the runtime does not have
502      * security access to read this property or the property does not exist.</p>
503      * 
504      * <p>
505      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
506      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
507      * will be out of sync with that System property.
508      * </p>
509      * 
510      * @since Java 1.2
511      */
512     public static final String JAVA_VM_NAME = getSystemProperty("java.vm.name");
513 
514     /**
515      * <p>The <code>java.vm.specification.name</code> System Property. Java Virtual Machine
516      * specification name.</p>
517      *
518      * <p>Defaults to <code>null</code> if the runtime does not have
519      * security access to read this property or the property does not exist.</p>
520      * 
521      * <p>
522      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
523      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
524      * will be out of sync with that System property.
525      * </p>
526      * 
527      * @since Java 1.2
528      */
529     public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty("java.vm.specification.name");
530 
531     /**
532      * <p>The <code>java.vm.specification.vendor</code> System Property. Java Virtual
533      * Machine specification vendor.</p>
534      *
535      * <p>Defaults to <code>null</code> if the runtime does not have
536      * security access to read this property or the property does not exist.</p>
537      * 
538      * <p>
539      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
540      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
541      * will be out of sync with that System property.
542      * </p>
543      * 
544      * @since Java 1.2
545      */
546     public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty("java.vm.specification.vendor");
547 
548     /**
549      * <p>The <code>java.vm.specification.version</code> System Property. Java Virtual Machine
550      * specification version.</p>
551      *
552      * <p>Defaults to <code>null</code> if the runtime does not have
553      * security access to read this property or the property does not exist.</p>
554      * 
555      * <p>
556      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
557      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
558      * will be out of sync with that System property.
559      * </p>
560      * 
561      * @since Java 1.2
562      */
563     public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty("java.vm.specification.version");
564 
565     /**
566      * <p>The <code>java.vm.vendor</code> System Property. Java Virtual Machine implementation
567      * vendor.</p>
568      *
569      * <p>Defaults to <code>null</code> if the runtime does not have
570      * security access to read this property or the property does not exist.</p>
571      * 
572      * <p>
573      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
574      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
575      * will be out of sync with that System property.
576      * </p>
577      * 
578      * @since Java 1.2
579      */
580     public static final String JAVA_VM_VENDOR = getSystemProperty("java.vm.vendor");
581 
582     /**
583      * <p>The <code>java.vm.version</code> System Property. Java Virtual Machine
584      * implementation version.</p>
585      *
586      * <p>Defaults to <code>null</code> if the runtime does not have
587      * security access to read this property or the property does not exist.</p>
588      * 
589      * <p>
590      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
591      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
592      * will be out of sync with that System property.
593      * </p>
594      * 
595      * @since Java 1.2
596      */
597     public static final String JAVA_VM_VERSION = getSystemProperty("java.vm.version");
598 
599     /**
600      * <p>The <code>line.separator</code> System Property. Line separator
601      * (<code>&quot;\n&quot;</code> on UNIX).</p>
602      *
603      * <p>Defaults to <code>null</code> if the runtime does not have
604      * security access to read this property or the property does not exist.</p>
605      * 
606      * <p>
607      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
608      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
609      * will be out of sync with that System property.
610      * </p>
611      * 
612      * @since Java 1.1
613      */
614     public static final String LINE_SEPARATOR = getSystemProperty("line.separator");
615 
616     /**
617      * <p>The <code>os.arch</code> System Property. Operating system architecture.</p>
618      *
619      * <p>Defaults to <code>null</code> if the runtime does not have
620      * security access to read this property or the property does not exist.</p>
621      * 
622      * <p>
623      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
624      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
625      * will be out of sync with that System property.
626      * </p>
627      * 
628      * @since Java 1.1
629      */
630     public static final String OS_ARCH = getSystemProperty("os.arch");
631 
632     /**
633      * <p>The <code>os.name</code> System Property. Operating system name.</p>
634      *
635      * <p>Defaults to <code>null</code> if the runtime does not have
636      * security access to read this property or the property does not exist.</p>
637      * 
638      * <p>
639      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
640      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
641      * will be out of sync with that System property.
642      * </p>
643      * 
644      * @since Java 1.1
645      */
646     public static final String OS_NAME = getSystemProperty("os.name");
647 
648     /**
649      * <p>The <code>os.version</code> System Property. Operating system version.</p>
650      *
651      * <p>Defaults to <code>null</code> if the runtime does not have
652      * security access to read this property or the property does not exist.</p>
653      * 
654      * <p>
655      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
656      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
657      * will be out of sync with that System property.
658      * </p>
659      * 
660      * @since Java 1.1
661      */
662     public static final String OS_VERSION = getSystemProperty("os.version");
663 
664     /**
665      * <p>The <code>path.separator</code> System Property. Path separator
666      * (<code>&quot;:&quot;</code> on UNIX).</p>
667      *
668      * <p>Defaults to <code>null</code> if the runtime does not have
669      * security access to read this property or the property does not exist.</p>
670      * 
671      * <p>
672      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
673      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
674      * will be out of sync with that System property.
675      * </p>
676      * 
677      * @since Java 1.1
678      */
679     public static final String PATH_SEPARATOR = getSystemProperty("path.separator");
680 
681     /**
682      * <p>The <code>user.country</code> or <code>user.region</code> System Property.
683      * User's country code, such as <code>GB</code>. First in JDK version 1.2 as
684      * <code>user.region</code>. Renamed to <code>user.country</code> in 1.4</p>
685      *
686      * <p>Defaults to <code>null</code> if the runtime does not have
687      * security access to read this property or the property does not exist.</p>
688      * 
689      * <p>
690      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
691      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
692      * will be out of sync with that System property.
693      * </p>
694      * 
695      * @since 2.0
696      * @since Java 1.2
697      */
698     public static final String USER_COUNTRY = 
699         getSystemProperty("user.country") == null ?
700             getSystemProperty("user.region") : getSystemProperty("user.country");
701 
702     /**
703      * <p>The <code>user.dir</code> System Property. User's current working
704      * directory.</p>
705      *
706      * <p>Defaults to <code>null</code> if the runtime does not have
707      * security access to read this property or the property does not exist.</p>
708      * 
709      * <p>
710      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
711      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
712      * will be out of sync with that System property.
713      * </p>
714      * 
715      * @since Java 1.1
716      */
717     public static final String USER_DIR = getSystemProperty(USER_DIR_KEY);
718 
719     /**
720      * <p>The <code>user.home</code> System Property. User's home directory.</p>
721      *
722      * <p>Defaults to <code>null</code> if the runtime does not have
723      * security access to read this property or the property does not exist.</p>
724      * 
725      * <p>
726      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
727      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
728      * will be out of sync with that System property.
729      * </p>
730      * 
731      * @since Java 1.1
732      */
733     public static final String USER_HOME = getSystemProperty(USER_HOME_KEY);
734 
735     /**
736      * <p>The <code>user.language</code> System Property. User's language code,
737      * such as <code>"en"</code>.</p>
738      *
739      * <p>Defaults to <code>null</code> if the runtime does not have
740      * security access to read this property or the property does not exist.</p>
741      * 
742      * <p>
743      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
744      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
745      * will be out of sync with that System property.
746      * </p>
747      * 
748      * @since 2.0
749      * @since Java 1.2
750      */
751     public static final String USER_LANGUAGE = getSystemProperty("user.language");
752 
753     /**
754      * <p>The <code>user.name</code> System Property. User's account name.</p>
755      *
756      * <p>Defaults to <code>null</code> if the runtime does not have
757      * security access to read this property or the property does not exist.</p>
758      * 
759      * <p>
760      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
761      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
762      * will be out of sync with that System property.
763      * </p>
764      * 
765      * @since Java 1.1
766      */
767     public static final String USER_NAME = getSystemProperty("user.name");
768 
769     /**
770      * <p>The <code>user.timezone</code> System Property. 
771      * For example: <code>"America/Los_Angeles"</code>.</p>
772      *
773      * <p>Defaults to <code>null</code> if the runtime does not have
774      * security access to read this property or the property does not exist.</p>
775      * 
776      * <p>
777      * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)}
778      * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value
779      * will be out of sync with that System property.
780      * </p>
781      * 
782      * @since 2.1
783      */
784     public static final String USER_TIMEZONE = getSystemProperty("user.timezone");
785 
786     // Java version
787     //-----------------------------------------------------------------------
788     // This MUST be declared after those above as it depends on the
789     // values being set up
790 
791     /**
792      * <p>Gets the Java version as a <code>String</code> trimming leading letters.</p>
793      *
794      * <p>The field will return <code>null</code> if {@link #JAVA_VERSION} is <code>null</code>.</p>
795      * 
796      * @since 2.1
797      */
798     public static final String JAVA_VERSION_TRIMMED = getJavaVersionTrimmed();
799 
800     // Java version values
801     //-----------------------------------------------------------------------
802     // These MUST be declared after the trim above as they depend on the
803     // value being set up
804 
805     /**
806      * <p>Gets the Java version as a <code>float</code>.</p>
807      *
808      * <p>Example return values:</p>
809      * <ul>
810      *  <li><code>1.2f</code> for JDK 1.2
811      *  <li><code>1.31f</code> for JDK 1.3.1
812      * </ul>
813      *
814      * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
815      * 
816      * @since 2.0
817      */
818     public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat();
819 
820     /**
821      * <p>Gets the Java version as an <code>int</code>.</p>
822      *
823      * <p>Example return values:</p>
824      * <ul>
825      *  <li><code>120</code> for JDK 1.2
826      *  <li><code>131</code> for JDK 1.3.1
827      * </ul>
828      *
829      * <p>The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.</p>
830      * 
831      * @since 2.0
832      */
833     public static final int JAVA_VERSION_INT = getJavaVersionAsInt();
834 
835     // Java version checks
836     //-----------------------------------------------------------------------
837     // These MUST be declared after those above as they depend on the
838     // values being set up
839     
840     /**
841      * <p>Is <code>true</code> if this is Java version 1.1 (also 1.1.x versions).</p>
842      *
843      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
844      * <code>null</code>.</p>
845      */
846     public static final boolean IS_JAVA_1_1 = getJavaVersionMatches("1.1");
847 
848     /**
849      * <p>Is <code>true</code> if this is Java version 1.2 (also 1.2.x versions).</p>
850      *
851      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
852      * <code>null</code>.</p>
853      */
854     public static final boolean IS_JAVA_1_2 = getJavaVersionMatches("1.2");
855 
856     /**
857      * <p>Is <code>true</code> if this is Java version 1.3 (also 1.3.x versions).</p>
858      *
859      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
860      * <code>null</code>.</p>
861      */
862     public static final boolean IS_JAVA_1_3 = getJavaVersionMatches("1.3");
863 
864     /**
865      * <p>Is <code>true</code> if this is Java version 1.4 (also 1.4.x versions).</p>
866      *
867      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
868      * <code>null</code>.</p>
869      */
870     public static final boolean IS_JAVA_1_4 = getJavaVersionMatches("1.4");
871 
872     /**
873      * <p>Is <code>true</code> if this is Java version 1.5 (also 1.5.x versions).</p>
874      *
875      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
876      * <code>null</code>.</p>
877      */
878     public static final boolean IS_JAVA_1_5 = getJavaVersionMatches("1.5");
879 
880     /**
881      * <p>Is <code>true</code> if this is Java version 1.6 (also 1.6.x versions).</p>
882      *
883      * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is
884      * <code>null</code>.</p>
885      */
886     public static final boolean IS_JAVA_1_6 = getJavaVersionMatches("1.6");
887 
888     // Operating system checks
889     //-----------------------------------------------------------------------
890     // These MUST be declared after those above as they depend on the
891     // values being set up
892     // OS names from http://www.vamphq.com/os.html
893     // Selected ones included - please advise dev@commons.apache.org
894     // if you want another added or a mistake corrected
895 
896     /**
897      * <p>Is <code>true</code> if this is AIX.</p>
898      *
899      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
900      * <code>null</code>.</p>
901      * 
902      * @since 2.0
903      */
904     public static final boolean IS_OS_AIX = getOSMatches("AIX");
905 
906     /**
907      * <p>Is <code>true</code> if this is HP-UX.</p>
908      *
909      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
910      * <code>null</code>.</p>
911      * 
912      * @since 2.0
913      */
914     public static final boolean IS_OS_HP_UX = getOSMatches("HP-UX");
915 
916     /**
917      * <p>Is <code>true</code> if this is Irix.</p>
918      *
919      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
920      * <code>null</code>.</p>
921      * 
922      * @since 2.0
923      */
924     public static final boolean IS_OS_IRIX = getOSMatches("Irix");
925 
926     /**
927      * <p>Is <code>true</code> if this is Linux.</p>
928      *
929      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
930      * <code>null</code>.</p>
931      * 
932      * @since 2.0
933      */
934     public static final boolean IS_OS_LINUX = getOSMatches("Linux") || getOSMatches("LINUX");
935 
936     /**
937      * <p>Is <code>true</code> if this is Mac.</p>
938      *
939      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
940      * <code>null</code>.</p>
941      * 
942      * @since 2.0
943      */
944     public static final boolean IS_OS_MAC = getOSMatches("Mac");
945 
946     /**
947      * <p>Is <code>true</code> if this is Mac.</p>
948      *
949      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
950      * <code>null</code>.</p>
951      * 
952      * @since 2.0
953      */
954     public static final boolean IS_OS_MAC_OSX = getOSMatches("Mac OS X");
955 
956     /**
957      * <p>Is <code>true</code> if this is OS/2.</p>
958      *
959      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
960      * <code>null</code>.</p>
961      * 
962      * @since 2.0
963      */
964     public static final boolean IS_OS_OS2 = getOSMatches("OS/2");
965 
966     /**
967      * <p>Is <code>true</code> if this is Solaris.</p>
968      *
969      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
970      * <code>null</code>.</p>
971      * 
972      * @since 2.0
973      */
974     public static final boolean IS_OS_SOLARIS = getOSMatches("Solaris");
975 
976     /**
977      * <p>Is <code>true</code> if this is SunOS.</p>
978      *
979      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
980      * <code>null</code>.</p>
981      * 
982      * @since 2.0
983      */
984     public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS");
985 
986     /**
987      * <p>Is <code>true</code> if this is a POSIX compilant system,
988      * as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.</p>
989      *
990      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
991      * <code>null</code>.</p>
992      * 
993      * @since 2.1
994      */
995     public static final boolean IS_OS_UNIX =
996         IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX ||
997         IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS;
998 
999     /**
1000      * <p>Is <code>true</code> if this is Windows.</p>
1001      *
1002      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1003      * <code>null</code>.</p>
1004      * 
1005      * @since 2.0
1006      */
1007     public static final boolean IS_OS_WINDOWS = getOSMatches(OS_NAME_WINDOWS_PREFIX);
1008 
1009     /**
1010      * <p>Is <code>true</code> if this is Windows 2000.</p>
1011      *
1012      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1013      * <code>null</code>.</p>
1014      * 
1015      * @since 2.0
1016      */
1017     public static final boolean IS_OS_WINDOWS_2000 = getOSMatches(OS_NAME_WINDOWS_PREFIX, "5.0");
1018 
1019     /**
1020      * <p>Is <code>true</code> if this is Windows 95.</p>
1021      *
1022      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1023      * <code>null</code>.</p>
1024      * 
1025      * @since 2.0
1026      */
1027     public static final boolean IS_OS_WINDOWS_95 = getOSMatches(OS_NAME_WINDOWS_PREFIX + " 9", "4.0");
1028     // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1029 
1030     /**
1031      * <p>Is <code>true</code> if this is Windows 98.</p>
1032      *
1033      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1034      * <code>null</code>.</p>
1035      * 
1036      * @since 2.0
1037      */
1038     public static final boolean IS_OS_WINDOWS_98 = getOSMatches(OS_NAME_WINDOWS_PREFIX + " 9", "4.1");
1039     // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1040 
1041     /**
1042      * <p>Is <code>true</code> if this is Windows ME.</p>
1043      *
1044      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1045      * <code>null</code>.</p>
1046      * 
1047      * @since 2.0
1048      */
1049     public static final boolean IS_OS_WINDOWS_ME = getOSMatches(OS_NAME_WINDOWS_PREFIX, "4.9");
1050     // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above
1051 
1052     /**
1053      * <p>Is <code>true</code> if this is Windows NT.</p>
1054      *
1055      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1056      * <code>null</code>.</p>
1057      * 
1058      * @since 2.0
1059      */
1060     public static final boolean IS_OS_WINDOWS_NT = getOSMatches(OS_NAME_WINDOWS_PREFIX + " NT");
1061     // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem
1062 
1063     /**
1064      * <p>Is <code>true</code> if this is Windows XP.</p>
1065      *
1066      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1067      * <code>null</code>.</p>
1068      * 
1069      * @since 2.0
1070      */
1071     public static final boolean IS_OS_WINDOWS_XP = getOSMatches(OS_NAME_WINDOWS_PREFIX, "5.1");
1072 
1073     //-----------------------------------------------------------------------    
1074     /**
1075      * <p>Is <code>true</code> if this is Windows Vista.</p>
1076      *
1077      * <p>The field will return <code>false</code> if <code>OS_NAME</code> is
1078      * <code>null</code>.</p>
1079      *
1080      * @since 2.4
1081      */
1082     public static final boolean IS_OS_WINDOWS_VISTA = getOSMatches(OS_NAME_WINDOWS_PREFIX, "6.0"); 
1083 
1084     //-----------------------------------------------------------------------    
1085     /**
1086      * <p>SystemUtils instances should NOT be constructed in standard
1087      * programming. Instead, the class should be used as
1088      * <code>SystemUtils.FILE_SEPARATOR</code>.</p>
1089      *
1090      * <p>This constructor is public to permit tools that require a JavaBean
1091      * instance to operate.</p>
1092      */
1093     public SystemUtils() {
1094         super();
1095     }
1096     
1097     //-----------------------------------------------------------------------    
1098     /**
1099      * <p>Gets the Java version number as a <code>float</code>.</p>
1100      *
1101      * <p>Example return values:</p>
1102      * <ul>
1103