001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 *
019 */
020 package org.apache.directory.shared.ldap.util;
021
022
023 import java.io.File;
024
025
026 /**
027 * <p>
028 * Helpers for <code>java.lang.System</code>.
029 * </p>
030 * <p>
031 * If a system property cannot be read due to security restrictions, the
032 * corresponding field in this class will be set to <code>null</code> and a
033 * message will be written to <code>System.err</code>.
034 * </p>
035 *
036 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
037 */
038 public class SystemUtils
039 {
040
041 /**
042 * The prefix String for all Windows OS.
043 */
044 private static final String OS_NAME_WINDOWS_PREFIX = "Windows";
045
046 // System property constants
047 // -----------------------------------------------------------------------
048 // These MUST be declared first. Other constants depend on this.
049
050 /**
051 * The System property key for the user home directory.
052 */
053 private static final String USER_HOME_KEY = "user.home";
054
055 /**
056 * The System property key for the user directory.
057 */
058 private static final String USER_DIR_KEY = "user.dir";
059
060 /**
061 * The System property key for the Java IO temporary directory.
062 */
063 private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir";
064
065 /**
066 * The System property key for the Java home directory.
067 */
068 private static final String JAVA_HOME_KEY = "java.home";
069
070 /**
071 * <p>
072 * The <code>awt.toolkit</code> System Property.
073 * </p>
074 * <p>
075 * Holds a class name, on Windows XP this is
076 * <code>sun.awt.windows.WToolkit</code>.
077 * </p>
078 * <p>
079 * <b>On platforms without a GUI, this value is <code>null</code>.</b>
080 * </p>
081 * <p>
082 * Defaults to <code>null</code> if the runtime does not have security
083 * access to read this property or the property does not exist.
084 * </p>
085 * <p>
086 * This value is initialized when the class is loaded. If
087 * {@link System#setProperty(String,String)} or
088 * {@link System#setProperties(java.util.Properties)} is called after this
089 * class is loaded, the value will be out of sync with that System property.
090 * </p>
091 *
092 * @since 2.1
093 */
094 public static final String AWT_TOOLKIT = getSystemProperty( "awt.toolkit" );
095
096 /**
097 * <p>
098 * The <code>file.encoding</code> System Property.
099 * </p>
100 * <p>
101 * File encoding, such as <code>Cp1252</code>.
102 * </p>
103 * <p>
104 * Defaults to <code>null</code> if the runtime does not have security
105 * access to read this property or the property does not exist.
106 * </p>
107 * <p>
108 * This value is initialized when the class is loaded. If
109 * {@link System#setProperty(String,String)} or
110 * {@link System#setProperties(java.util.Properties)} is called after this
111 * class is loaded, the value will be out of sync with that System property.
112 * </p>
113 *
114 * @since 2.0
115 * @since Java 1.2
116 */
117 public static final String FILE_ENCODING = getSystemProperty( "file.encoding" );
118
119 /**
120 * <p>
121 * The <code>file.separator</code> System Property. File separator (<code>"/"</code>
122 * on UNIX).
123 * </p>
124 * <p>
125 * Defaults to <code>null</code> if the runtime does not have security
126 * access to read this property or the property does not exist.
127 * </p>
128 * <p>
129 * This value is initialized when the class is loaded. If
130 * {@link System#setProperty(String,String)} or
131 * {@link System#setProperties(java.util.Properties)} is called after this
132 * class is loaded, the value will be out of sync with that System property.
133 * </p>
134 *
135 * @since Java 1.1
136 */
137 public static final String FILE_SEPARATOR = getSystemProperty( "file.separator" );
138
139 /**
140 * <p>
141 * The <code>java.awt.fonts</code> System Property.
142 * </p>
143 * <p>
144 * Defaults to <code>null</code> if the runtime does not have security
145 * access to read this property or the property does not exist.
146 * </p>
147 * <p>
148 * This value is initialized when the class is loaded. If
149 * {@link System#setProperty(String,String)} or
150 * {@link System#setProperties(java.util.Properties)} is called after this
151 * class is loaded, the value will be out of sync with that System property.
152 * </p>
153 *
154 * @since 2.1
155 */
156 public static final String JAVA_AWT_FONTS = getSystemProperty( "java.awt.fonts" );
157
158 /**
159 * <p>
160 * The <code>java.awt.graphicsenv</code> System Property.
161 * </p>
162 * <p>
163 * Defaults to <code>null</code> if the runtime does not have security
164 * access to read this property or the property does not exist.
165 * </p>
166 * <p>
167 * This value is initialized when the class is loaded. If
168 * {@link System#setProperty(String,String)} or
169 * {@link System#setProperties(java.util.Properties)} is called after this
170 * class is loaded, the value will be out of sync with that System property.
171 * </p>
172 *
173 * @since 2.1
174 */
175 public static final String JAVA_AWT_GRAPHICSENV = getSystemProperty( "java.awt.graphicsenv" );
176
177 /**
178 * <p>
179 * The <code>java.awt.headless</code> System Property. The value of this
180 * property is the String <code>"true"</code> or <code>"false"</code>.
181 * </p>
182 * <p>
183 * Defaults to <code>null</code> if the runtime does not have security
184 * access to read this property or the property does not exist.
185 * </p>
186 * <p>
187 * This value is initialized when the class is loaded. If
188 * {@link System#setProperty(String,String)} or
189 * {@link System#setProperties(java.util.Properties)} is called after this
190 * class is loaded, the value will be out of sync with that System property.
191 * </p>
192 *
193 * @see #isJavaAwtHeadless()
194 * @since 2.1
195 * @since Java 1.4
196 */
197 public static final String JAVA_AWT_HEADLESS = getSystemProperty( "java.awt.headless" );
198
199 /**
200 * <p>
201 * The <code>java.awt.printerjob</code> System Property.
202 * </p>
203 * <p>
204 * Defaults to <code>null</code> if the runtime does not have security
205 * access to read this property or the property does not exist.
206 * </p>
207 * <p>
208 * This value is initialized when the class is loaded. If
209 * {@link System#setProperty(String,String)} or
210 * {@link System#setProperties(java.util.Properties)} is called after this
211 * class is loaded, the value will be out of sync with that System property.
212 * </p>
213 *
214 * @since 2.1
215 */
216 public static final String JAVA_AWT_PRINTERJOB = getSystemProperty( "java.awt.printerjob" );
217
218 /**
219 * <p>
220 * The <code>java.class.path</code> System Property. Java class path.
221 * </p>
222 * <p>
223 * Defaults to <code>null</code> if the runtime does not have security
224 * access to read this property or the property does not exist.
225 * </p>
226 * <p>
227 * This value is initialized when the class is loaded. If
228 * {@link System#setProperty(String,String)} or
229 * {@link System#setProperties(java.util.Properties)} is called after this
230 * class is loaded, the value will be out of sync with that System property.
231 * </p>
232 *
233 * @since Java 1.1
234 */
235 public static final String JAVA_CLASS_PATH = getSystemProperty( "java.class.path" );
236
237 /**
238 * <p>
239 * The <code>java.class.version</code> System Property. Java class format
240 * version number.
241 * </p>
242 * <p>
243 * Defaults to <code>null</code> if the runtime does not have security
244 * access to read this property or the property does not exist.
245 * </p>
246 * <p>
247 * This value is initialized when the class is loaded. If
248 * {@link System#setProperty(String,String)} or
249 * {@link System#setProperties(java.util.Properties)} is called after this
250 * class is loaded, the value will be out of sync with that System property.
251 * </p>
252 *
253 * @since Java 1.1
254 */
255 public static final String JAVA_CLASS_VERSION = getSystemProperty( "java.class.version" );
256
257 /**
258 * <p>
259 * The <code>java.compiler</code> System Property. Name of JIT compiler to
260 * use. First in JDK version 1.2. Not used in Sun JDKs after 1.2.
261 * </p>
262 * <p>
263 * Defaults to <code>null</code> if the runtime does not have security
264 * access to read this property or the property does not exist.
265 * </p>
266 * <p>
267 * This value is initialized when the class is loaded. If
268 * {@link System#setProperty(String,String)} or
269 * {@link System#setProperties(java.util.Properties)} is called after this
270 * class is loaded, the value will be out of sync with that System property.
271 * </p>
272 *
273 * @since Java 1.2. Not used in Sun versions after 1.2.
274 */
275 public static final String JAVA_COMPILER = getSystemProperty( "java.compiler" );
276
277 /**
278 * <p>
279 * The <code>java.endorsed.dirs</code> System Property. Path of endorsed
280 * directory or directories.
281 * </p>
282 * <p>
283 * Defaults to <code>null</code> if the runtime does not have security
284 * access to read this property or the property does not exist.
285 * </p>
286 * <p>
287 * This value is initialized when the class is loaded. If
288 * {@link System#setProperty(String,String)} or
289 * {@link System#setProperties(java.util.Properties)} is called after this
290 * class is loaded, the value will be out of sync with that System property.
291 * </p>
292 *
293 * @since Java 1.4
294 */
295 public static final String JAVA_ENDORSED_DIRS = getSystemProperty( "java.endorsed.dirs" );
296
297 /**
298 * <p>
299 * The <code>java.ext.dirs</code> System Property. Path of extension
300 * directory or directories.
301 * </p>
302 * <p>
303 * Defaults to <code>null</code> if the runtime does not have security
304 * access to read this property or the property does not exist.
305 * </p>
306 * <p>
307 * This value is initialized when the class is loaded. If
308 * {@link System#setProperty(String,String)} or
309 * {@link System#setProperties(java.util.Properties)} is called after this
310 * class is loaded, the value will be out of sync with that System property.
311 * </p>
312 *
313 * @since Java 1.3
314 */
315 public static final String JAVA_EXT_DIRS = getSystemProperty( "java.ext.dirs" );
316
317 /**
318 * <p>
319 * The <code>java.home</code> System Property. Java installation
320 * directory.
321 * </p>
322 * <p>
323 * Defaults to <code>null</code> if the runtime does not have security
324 * access to read this property or the property does not exist.
325 * </p>
326 * <p>
327 * This value is initialized when the class is loaded. If
328 * {@link System#setProperty(String,String)} or
329 * {@link System#setProperties(java.util.Properties)} is called after this
330 * class is loaded, the value will be out of sync with that System property.
331 * </p>
332 *
333 * @since Java 1.1
334 */
335 public static final String JAVA_HOME = getSystemProperty( JAVA_HOME_KEY );
336
337 /**
338 * <p>
339 * The <code>java.io.tmpdir</code> System Property. Default temp file
340 * path.
341 * </p>
342 * <p>
343 * Defaults to <code>null</code> if the runtime does not have security
344 * access to read this property or the property does not exist.
345 * </p>
346 * <p>
347 * This value is initialized when the class is loaded. If
348 * {@link System#setProperty(String,String)} or
349 * {@link System#setProperties(java.util.Properties)} is called after this
350 * class is loaded, the value will be out of sync with that System property.
351 * </p>
352 *
353 * @since Java 1.2
354 */
355 public static final String JAVA_IO_TMPDIR = getSystemProperty( JAVA_IO_TMPDIR_KEY );
356
357 /**
358 * <p>
359 * The <code>java.library.path</code> System Property. List of paths to
360 * search when loading libraries.
361 * </p>
362 * <p>
363 * Defaults to <code>null</code> if the runtime does not have security
364 * access to read this property or the property does not exist.
365 * </p>
366 * <p>
367 * This value is initialized when the class is loaded. If
368 * {@link System#setProperty(String,String)} or
369 * {@link System#setProperties(java.util.Properties)} is called after this
370 * class is loaded, the value will be out of sync with that System property.
371 * </p>
372 *
373 * @since Java 1.2
374 */
375 public static final String JAVA_LIBRARY_PATH = getSystemProperty( "java.library.path" );
376
377 /**
378 * <p>
379 * The <code>java.runtime.name</code> System Property. Java Runtime
380 * Environment name.
381 * </p>
382 * <p>
383 * Defaults to <code>null</code> if the runtime does not have security
384 * access to read this property or the property does not exist.
385 * </p>
386 * <p>
387 * This value is initialized when the class is loaded. If
388 * {@link System#setProperty(String,String)} or
389 * {@link System#setProperties(java.util.Properties)} is called after this
390 * class is loaded, the value will be out of sync with that System property.
391 * </p>
392 *
393 * @since 2.0
394 * @since Java 1.3
395 */
396 public static final String JAVA_RUNTIME_NAME = getSystemProperty( "java.runtime.name" );
397
398 /**
399 * <p>
400 * The <code>java.runtime.version</code> System Property. Java Runtime
401 * Environment version.
402 * </p>
403 * <p>
404 * Defaults to <code>null</code> if the runtime does not have security
405 * access to read this property or the property does not exist.
406 * </p>
407 * <p>
408 * This value is initialized when the class is loaded. If
409 * {@link System#setProperty(String,String)} or
410 * {@link System#setProperties(java.util.Properties)} is called after this
411 * class is loaded, the value will be out of sync with that System property.
412 * </p>
413 *
414 * @since 2.0
415 * @since Java 1.3
416 */
417 public static final String JAVA_RUNTIME_VERSION = getSystemProperty( "java.runtime.version" );
418
419 /**
420 * <p>
421 * The <code>java.specification.name</code> System Property. Java Runtime
422 * Environment specification name.
423 * </p>
424 * <p>
425 * Defaults to <code>null</code> if the runtime does not have security
426 * access to read this property or the property does not exist.
427 * </p>
428 * <p>
429 * This value is initialized when the class is loaded. If
430 * {@link System#setProperty(String,String)} or
431 * {@link System#setProperties(java.util.Properties)} is called after this
432 * class is loaded, the value will be out of sync with that System property.
433 * </p>
434 *
435 * @since Java 1.2
436 */
437 public static final String JAVA_SPECIFICATION_NAME = getSystemProperty( "java.specification.name" );
438
439 /**
440 * <p>
441 * The <code>java.specification.vendor</code> System Property. Java
442 * Runtime Environment specification vendor.
443 * </p>
444 * <p>
445 * Defaults to <code>null</code> if the runtime does not have security
446 * access to read this property or the property does not exist.
447 * </p>
448 * <p>
449 * This value is initialized when the class is loaded. If
450 * {@link System#setProperty(String,String)} or
451 * {@link System#setProperties(java.util.Properties)} is called after this
452 * class is loaded, the value will be out of sync with that System property.
453 * </p>
454 *
455 * @since Java 1.2
456 */
457 public static final String JAVA_SPECIFICATION_VENDOR = getSystemProperty( "java.specification.vendor" );
458
459 /**
460 * <p>
461 * The <code>java.specification.version</code> System Property. Java
462 * Runtime Environment specification version.
463 * </p>
464 * <p>
465 * Defaults to <code>null</code> if the runtime does not have security
466 * access to read this property or the property does not exist.
467 * </p>
468 * <p>
469 * This value is initialized when the class is loaded. If
470 * {@link System#setProperty(String,String)} or
471 * {@link System#setProperties(java.util.Properties)} is called after this
472 * class is loaded, the value will be out of sync with that System property.
473 * </p>
474 *
475 * @since Java 1.3
476 */
477 public static final String JAVA_SPECIFICATION_VERSION = getSystemProperty( "java.specification.version" );
478
479 /**
480 * <p>
481 * The <code>java.util.prefs.PreferencesFactory</code> System Property. A
482 * class name.
483 * </p>
484 * <p>
485 * Defaults to <code>null</code> if the runtime does not have security
486 * access to read this property or the property does not exist.
487 * </p>
488 * <p>
489 * This value is initialized when the class is loaded. If
490 * {@link System#setProperty(String,String)} or
491 * {@link System#setProperties(java.util.Properties)} is called after this
492 * class is loaded, the value will be out of sync with that System property.
493 * </p>
494 *
495 * @since 2.1
496 * @since Java 1.4
497 */
498 public static final String JAVA_UTIL_PREFS_PREFERENCES_FACTORY = getSystemProperty( "java.util.prefs.PreferencesFactory" );
499
500 /**
501 * <p>
502 * The <code>java.vendor</code> System Property. Java vendor-specific
503 * string.
504 * </p>
505 * <p>
506 * Defaults to <code>null</code> if the runtime does not have security
507 * access to read this property or the property does not exist.
508 * </p>
509 * <p>
510 * This value is initialized when the class is loaded. If
511 * {@link System#setProperty(String,String)} or
512 * {@link System#setProperties(java.util.Properties)} is called after this
513 * class is loaded, the value will be out of sync with that System property.
514 * </p>
515 *
516 * @since Java 1.1
517 */
518 public static final String JAVA_VENDOR = getSystemProperty( "java.vendor" );
519
520 /**
521 * <p>
522 * The <code>java.vendor.url</code> System Property. Java vendor URL.
523 * </p>
524 * <p>
525 * Defaults to <code>null</code> if the runtime does not have security
526 * access to read this property or the property does not exist.
527 * </p>
528 * <p>
529 * This value is initialized when the class is loaded. If
530 * {@link System#setProperty(String,String)} or
531 * {@link System#setProperties(java.util.Properties)} is called after this
532 * class is loaded, the value will be out of sync with that System property.
533 * </p>
534 *
535 * @since Java 1.1
536 */
537 public static final String JAVA_VENDOR_URL = getSystemProperty( "java.vendor.url" );
538
539 /**
540 * <p>
541 * The <code>java.version</code> System Property. Java version number.
542 * </p>
543 * <p>
544 * Defaults to <code>null</code> if the runtime does not have security
545 * access to read this property or the property does not exist.
546 * </p>
547 * <p>
548 * This value is initialized when the class is loaded. If
549 * {@link System#setProperty(String,String)} or
550 * {@link System#setProperties(java.util.Properties)} is called after this
551 * class is loaded, the value will be out of sync with that System property.
552 * </p>
553 *
554 * @since Java 1.1
555 */
556 public static final String JAVA_VERSION = getSystemProperty( "java.version" );
557
558 /**
559 * <p>
560 * The <code>java.vm.info</code> System Property. Java Virtual Machine
561 * implementation info.
562 * </p>
563 * <p>
564 * Defaults to <code>null</code> if the runtime does not have security
565 * access to read this property or the property does not exist.
566 * </p>
567 * <p>
568 * This value is initialized when the class is loaded. If
569 * {@link System#setProperty(String,String)} or
570 * {@link System#setProperties(java.util.Properties)} is called after this
571 * class is loaded, the value will be out of sync with that System property.
572 * </p>
573 *
574 * @since 2.0
575 * @since Java 1.2
576 */
577 public static final String JAVA_VM_INFO = getSystemProperty( "java.vm.info" );
578
579 /**
580 * <p>
581 * The <code>java.vm.name</code> System Property. Java Virtual Machine
582 * implementation name.
583 * </p>
584 * <p>
585 * Defaults to <code>null</code> if the runtime does not have security
586 * access to read this property or the property does not exist.
587 * </p>
588 * <p>
589 * This value is initialized when the class is loaded. If
590 * {@link System#setProperty(String,String)} or
591 * {@link System#setProperties(java.util.Properties)} is called after this
592 * class is loaded, the value 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_NAME = getSystemProperty( "java.vm.name" );
598
599 /**
600 * <p>
601 * The <code>java.vm.specification.name</code> System Property. Java
602 * Virtual Machine specification name.
603 * </p>
604 * <p>
605 * Defaults to <code>null</code> if the runtime does not have security
606 * access to read this property or the property does not exist.
607 * </p>
608 * <p>
609 * This value is initialized when the class is loaded. If
610 * {@link System#setProperty(String,String)} or
611 * {@link System#setProperties(java.util.Properties)} is called after this
612 * class is loaded, the value will be out of sync with that System property.
613 * </p>
614 *
615 * @since Java 1.2
616 */
617 public static final String JAVA_VM_SPECIFICATION_NAME = getSystemProperty( "java.vm.specification.name" );
618
619 /**
620 * <p>
621 * The <code>java.vm.specification.vendor</code> System Property. Java
622 * Virtual Machine specification vendor.
623 * </p>
624 * <p>
625 * Defaults to <code>null</code> if the runtime does not have security
626 * access to read this property or the property does not exist.
627 * </p>
628 * <p>
629 * This value is initialized when the class is loaded. If
630 * {@link System#setProperty(String,String)} or
631 * {@link System#setProperties(java.util.Properties)} is called after this
632 * class is loaded, the value will be out of sync with that System property.
633 * </p>
634 *
635 * @since Java 1.2
636 */
637 public static final String JAVA_VM_SPECIFICATION_VENDOR = getSystemProperty( "java.vm.specification.vendor" );
638
639 /**
640 * <p>
641 * The <code>java.vm.specification.version</code> System Property. Java
642 * Virtual Machine specification version.
643 * </p>
644 * <p>
645 * Defaults to <code>null</code> if the runtime does not have security
646 * access to read this property or the property does not exist.
647 * </p>
648 * <p>
649 * This value is initialized when the class is loaded. If
650 * {@link System#setProperty(String,String)} or
651 * {@link System#setProperties(java.util.Properties)} is called after this
652 * class is loaded, the value will be out of sync with that System property.
653 * </p>
654 *
655 * @since Java 1.2
656 */
657 public static final String JAVA_VM_SPECIFICATION_VERSION = getSystemProperty( "java.vm.specification.version" );
658
659 /**
660 * <p>
661 * The <code>java.vm.vendor</code> System Property. Java Virtual Machine
662 * implementation vendor.
663 * </p>
664 * <p>
665 * Defaults to <code>null</code> if the runtime does not have security
666 * access to read this property or the property does not exist.
667 * </p>
668 * <p>
669 * This value is initialized when the class is loaded. If
670 * {@link System#setProperty(String,String)} or
671 * {@link System#setProperties(java.util.Properties)} is called after this
672 * class is loaded, the value will be out of sync with that System property.
673 * </p>
674 *
675 * @since Java 1.2
676 */
677 public static final String JAVA_VM_VENDOR = getSystemProperty( "java.vm.vendor" );
678
679 /**
680 * <p>
681 * The <code>java.vm.version</code> System Property. Java Virtual Machine
682 * implementation version.
683 * </p>
684 * <p>
685 * Defaults to <code>null</code> if the runtime does not have security
686 * access to read this property or the property does not exist.
687 * </p>
688 * <p>
689 * This value is initialized when the class is loaded. If
690 * {@link System#setProperty(String,String)} or
691 * {@link System#setProperties(java.util.Properties)} is called after this
692 * class is loaded, the value will be out of sync with that System property.
693 * </p>
694 *
695 * @since Java 1.2
696 */
697 public static final String JAVA_VM_VERSION = getSystemProperty( "java.vm.version" );
698
699 /**
700 * <p>
701 * The <code>line.separator</code> System Property. Line separator (<code>"\n<"</code>
702 * on UNIX).
703 * </p>
704 * <p>
705 * Defaults to <code>null</code> if the runtime does not have security
706 * access to read this property or the property does not exist.
707 * </p>
708 * <p>
709 * This value is initialized when the class is loaded. If
710 * {@link System#setProperty(String,String)} or
711 * {@link System#setProperties(java.util.Properties)} is called after this
712 * class is loaded, the value will be out of sync with that System property.
713 * </p>
714 *
715 * @since Java 1.1
716 */
717 public static final String LINE_SEPARATOR = getSystemProperty( "line.separator" );
718
719 /**
720 * <p>
721 * The <code>os.arch</code> System Property. Operating system
722 * architecture.
723 * </p>
724 * <p>
725 * Defaults to <code>null</code> if the runtime does not have security
726 * access to read this property or the property does not exist.
727 * </p>
728 * <p>
729 * This value is initialized when the class is loaded. If
730 * {@link System#setProperty(String,String)} or
731 * {@link System#setProperties(java.util.Properties)} is called after this
732 * class is loaded, the value will be out of sync with that System property.
733 * </p>
734 *
735 * @since Java 1.1
736 */
737 public static final String OS_ARCH = getSystemProperty( "os.arch" );
738
739 /**
740 * <p>
741 * The <code>os.name</code> System Property. Operating system name.
742 * </p>
743 * <p>
744 * Defaults to <code>null</code> if the runtime does not have security
745 * access to read this property or the property does not exist.
746 * </p>
747 * <p>
748 * This value is initialized when the class is loaded. If
749 * {@link System#setProperty(String,String)} or
750 * {@link System#setProperties(java.util.Properties)} is called after this
751 * class is loaded, the value will be out of sync with that System property.
752 * </p>
753 *
754 * @since Java 1.1
755 */
756 public static final String OS_NAME = getSystemProperty( "os.name" );
757
758 /**
759 * <p>
760 * The <code>os.version</code> System Property. Operating system version.
761 * </p>
762 * <p>
763 * Defaults to <code>null</code> if the runtime does not have security
764 * access to read this property or the property does not exist.
765 * </p>
766 * <p>
767 * This value is initialized when the class is loaded. If
768 * {@link System#setProperty(String,String)} or
769 * {@link System#setProperties(java.util.Properties)} is called after this
770 * class is loaded, the value will be out of sync with that System property.
771 * </p>
772 *
773 * @since Java 1.1
774 */
775 public static final String OS_VERSION = getSystemProperty( "os.version" );
776
777 /**
778 * <p>
779 * The <code>path.separator</code> System Property. Path separator (<code>":"</code>
780 * on UNIX).
781 * </p>
782 * <p>
783 * Defaults to <code>null</code> if the runtime does not have security
784 * access to read this property or the property does not exist.
785 * </p>
786 * <p>
787 * This value is initialized when the class is loaded. If
788 * {@link System#setProperty(String,String)} or
789 * {@link System#setProperties(java.util.Properties)} is called after this
790 * class is loaded, the value will be out of sync with that System property.
791 * </p>
792 *
793 * @since Java 1.1
794 */
795 public static final String PATH_SEPARATOR = getSystemProperty( "path.separator" );
796
797 /**
798 * <p>
799 * The <code>user.country</code> or <code>user.region</code> System
800 * Property. User's country code, such as <code>GB</code>. First in JDK
801 * version 1.2 as <code>user.region</code>. Renamed to
802 * <code>user.country</code> in 1.4
803 * </p>
804 * <p>
805 * Defaults to <code>null</code> if the runtime does not have security
806 * access to read this property or the property does not exist.
807 * </p>
808 * <p>
809 * This value is initialized when the class is loaded. If
810 * {@link System#setProperty(String,String)} or
811 * {@link System#setProperties(java.util.Properties)} is called after this
812 * class is loaded, the value will be out of sync with that System property.
813 * </p>
814 *
815 * @since 2.0
816 * @since Java 1.2
817 */
818 public static final String USER_COUNTRY = ( getSystemProperty( "user.country" ) == null ? getSystemProperty( "user.region" )
819 : getSystemProperty( "user.country" ) );
820
821 /**
822 * <p>
823 * The <code>user.dir</code> System Property. User's current working
824 * directory.
825 * </p>
826 * <p>
827 * Defaults to <code>null</code> if the runtime does not have security
828 * access to read this property or the property does not exist.
829 * </p>
830 * <p>
831 * This value is initialized when the class is loaded. If
832 * {@link System#setProperty(String,String)} or
833 * {@link System#setProperties(java.util.Properties)} is called after this
834 * class is loaded, the value will be out of sync with that System property.
835 * </p>
836 *
837 * @since Java 1.1
838 */
839 public static final String USER_DIR = getSystemProperty( USER_DIR_KEY );
840
841 /**
842 * <p>
843 * The <code>user.home</code> System Property. User's home directory.
844 * </p>
845 * <p>
846 * Defaults to <code>null</code> if the runtime does not have security
847 * access to read this property or the property does not exist.
848 * </p>
849 * <p>
850 * This value is initialized when the class is loaded. If
851 * {@link System#setProperty(String,String)} or
852 * {@link System#setProperties(java.util.Properties)} is called after this
853 * class is loaded, the value will be out of sync with that System property.
854 * </p>
855 *
856 * @since Java 1.1
857 */
858 public static final String USER_HOME = getSystemProperty( USER_HOME_KEY );
859
860 /**
861 * <p>
862 * The <code>user.language</code> System Property. User's language code,
863 * such as <code>"en"</code>.
864 * </p>
865 * <p>
866 * Defaults to <code>null</code> if the runtime does not have security
867 * access to read this property or the property does not exist.
868 * </p>
869 * <p>
870 * This value is initialized when the class is loaded. If
871 * {@link System#setProperty(String,String)} or
872 * {@link System#setProperties(java.util.Properties)} is called after this
873 * class is loaded, the value will be out of sync with that System property.
874 * </p>
875 *
876 * @since 2.0
877 * @since Java 1.2
878 */
879 public static final String USER_LANGUAGE = getSystemProperty( "user.language" );
880
881 /**
882 * <p>
883 * The <code>user.name</code> System Property. User's account name.
884 * </p>
885 * <p>
886 * Defaults to <code>null</code> if the runtime does not have security
887 * access to read this property or the property does not exist.
888 * </p>
889 * <p>
890 * This value is initialized when the class is loaded. If
891 * {@link System#setProperty(String,String)} or
892 * {@link System#setProperties(java.util.Properties)} is called after this
893 * class is loaded, the value will be out of sync with that System property.
894 * </p>
895 *
896 * @since Java 1.1
897 */
898 public static final String USER_NAME = getSystemProperty( "user.name" );
899
900 /**
901 * <p>
902 * The <code>user.timezone</code> System Property. For example:
903 * <code>"America/Los_Angeles"</code>.
904 * </p>
905 * <p>
906 * Defaults to <code>null</code> if the runtime does not have security
907 * access to read this property or the property does not exist.
908 * </p>
909 * <p>
910 * This value is initialized when the class is loaded. If
911 * {@link System#setProperty(String,String)} or
912 * {@link System#setProperties(java.util.Properties)} is called after this
913 * class is loaded, the value will be out of sync with that System property.
914 * </p>
915 *
916 * @since 2.1
917 */
918 public static final String USER_TIMEZONE = getSystemProperty( "user.timezone" );
919
920 // Java version
921 // -----------------------------------------------------------------------
922 // These MUST be declared after those above as they depend on the
923 // values being set up
924
925 /**
926 * <p>
927 * Gets the Java version as a <code>float</code>.
928 * </p>
929 * <p>
930 * Example return values:
931 * </p>
932 * <ul>
933 * <li><code>1.2f</code> for JDK 1.2
934 * <li><code>1.31f</code> for JDK 1.3.1
935 * </ul>
936 * <p>
937 * The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.
938 * </p>
939 *
940 * @since 2.0
941 */
942 public static final float JAVA_VERSION_FLOAT = getJavaVersionAsFloat();
943
944 /**
945 * <p>
946 * Gets the Java version as an <code>int</code>.
947 * </p>
948 * <p>
949 * Example return values:
950 * </p>
951 * <ul>
952 * <li><code>120</code> for JDK 1.2
953 * <li><code>131</code> for JDK 1.3.1
954 * </ul>
955 * <p>
956 * The field will return zero if {@link #JAVA_VERSION} is <code>null</code>.
957 * </p>
958 *
959 * @since 2.0
960 */
961 public static final int JAVA_VERSION_INT = getJavaVersionAsInt();
962
963 // Java version checks
964 // -----------------------------------------------------------------------
965 // These MUST be declared after those above as they depend on the
966 // values being set up
967
968 /**
969 * <p>
970 * Is <code>true</code> if this is Java version 1.1 (also 1.1.x versions).
971 * </p>
972 * <p>
973 * The field will return <code>false</code> if {@link #JAVA_VERSION} is
974 * <code>null</code>.
975 * </p>
976 */
977 public static final boolean IS_JAVA_1_1 = getJavaVersionMatches( "1.1" );
978
979 /**
980 * <p>
981 * Is <code>true</code> if this is Java version 1.2 (also 1.2.x versions).
982 * </p>
983 * <p>
984 * The field will return <code>false</code> if {@link #JAVA_VERSION} is
985 * <code>null</code>.
986 * </p>
987 */
988 public static final boolean IS_JAVA_1_2 = getJavaVersionMatches( "1.2" );
989
990 /**
991 * <p>
992 * Is <code>true</code> if this is Java version 1.3 (also 1.3.x versions).
993 * </p>
994 * <p>
995 * The field will return <code>false</code> if {@link #JAVA_VERSION} is
996 * <code>null</code>.
997 * </p>
998 */
999 public static final boolean IS_JAVA_1_3 = getJavaVersionMatches( "1.3" );
1000
1001 /**
1002 * <p>
1003 * Is <code>true</code> if this is Java version 1.4 (also 1.4.x versions).
1004 * </p>
1005 * <p>
1006 * The field will return <code>false</code> if {@link #JAVA_VERSION} is
1007 * <code>null</code>.
1008 * </p>
1009 */
1010 public static final boolean IS_JAVA_1_4 = getJavaVersionMatches( "1.4" );
1011
1012 /**
1013 * <p>
1014 * Is <code>true</code> if this is Java version 1.5 (also 1.5.x versions).
1015 * </p>
1016 * <p>
1017 * The field will return <code>false</code> if {@link #JAVA_VERSION} is
1018 * <code>null</code>.
1019 * </p>
1020 */
1021 public static final boolean IS_JAVA_1_5 = getJavaVersionMatches( "1.5" );
1022
1023 // Operating system checks
1024 // -----------------------------------------------------------------------
1025 // These MUST be declared after those above as they depend on the
1026 // values being set up
1027 // OS names from http://www.vamphq.com/os.html
1028 // Selected ones included - please advise commons-dev@jakarta.apache.org
1029 // if you want another added or a mistake corrected
1030
1031 /**
1032 * <p>
1033 * Is <code>true</code> if this is AIX.
1034 * </p>
1035 * <p>
1036 * The field will return <code>false</code> if <code>OS_NAME</code> is
1037 * <code>null</code>.
1038 * </p>
1039 *
1040 * @since 2.0
1041 */
1042 public static final boolean IS_OS_AIX = getOSMatches( "AIX" );
1043
1044 /**
1045 * <p>
1046 * Is <code>true</code> if this is HP-UX.
1047 * </p>
1048 * <p>
1049 * The field will return <code>false</code> if <code>OS_NAME</code> is
1050 * <code>null</code>.
1051 * </p>
1052 *
1053 * @since 2.0
1054 */
1055 public static final boolean IS_OS_HP_UX = getOSMatches( "HP-UX" );
1056
1057 /**
1058 * <p>
1059 * Is <code>true</code> if this is Irix.
1060 * </p>
1061 * <p>
1062 * The field will return <code>false</code> if <code>OS_NAME</code> is
1063 * <code>null</code>.
1064 * </p>
1065 *
1066 * @since 2.0
1067 */
1068 public static final boolean IS_OS_IRIX = getOSMatches( "Irix" );
1069
1070 /**
1071 * <p>
1072 * Is <code>true</code> if this is Linux.
1073 * </p>
1074 * <p>
1075 * The field will return <code>false</code> if <code>OS_NAME</code> is
1076 * <code>null</code>.
1077 * </p>
1078 *
1079 * @since 2.0
1080 */
1081 public static final boolean IS_OS_LINUX = getOSMatches( "Linux" ) || getOSMatches( "LINUX" );
1082
1083 /**
1084 * <p>
1085 * Is <code>true</code> if this is Mac.
1086 * </p>
1087 * <p>
1088 * The field will return <code>false</code> if <code>OS_NAME</code> is
1089 * <code>null</code>.
1090 * </p>
1091 *
1092 * @since 2.0
1093 */
1094 public static final boolean IS_OS_MAC = getOSMatches( "Mac" );
1095
1096 /**
1097 * <p>
1098 * Is <code>true</code> if this is Mac.
1099 * </p>
1100 * <p>
1101 * The field will return <code>false</code> if <code>OS_NAME</code> is
1102 * <code>null</code>.
1103 * </p>
1104 *
1105 * @since 2.0
1106 */
1107 public static final boolean IS_OS_MAC_OSX = getOSMatches( "Mac OS X" );
1108
1109 /**
1110 * <p>
1111 * Is <code>true</code> if this is OS/2.
1112 * </p>
1113 * <p>
1114 * The field will return <code>false</code> if <code>OS_NAME</code> is
1115 * <code>null</code>.
1116 * </p>
1117 *
1118 * @since 2.0
1119 */
1120 public static final boolean IS_OS_OS2 = getOSMatches( "OS/2" );
1121
1122 /**
1123 * <p>
1124 * Is <code>true</code> if this is Solaris.
1125 * </p>
1126 * <p>
1127 * The field will return <code>false</code> if <code>OS_NAME</code> is
1128 * <code>null</code>.
1129 * </p>
1130 *
1131 * @since 2.0
1132 */
1133 public static final boolean IS_OS_SOLARIS = getOSMatches( "Solaris" );
1134
1135 /**
1136 * <p>
1137 * Is <code>true</code> if this is SunOS.
1138 * </p>
1139 * <p>
1140 * The field will return <code>false</code> if <code>OS_NAME</code> is
1141 * <code>null</code>.
1142 * </p>
1143 *
1144 * @since 2.0
1145 */
1146 public static final boolean IS_OS_SUN_OS = getOSMatches( "SunOS" );
1147
1148 /**
1149 * <p>
1150 * Is <code>true</code> if this is a POSIX compilant system, as in any of
1151 * AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.
1152 * </p>
1153 * <p>
1154 * The field will return <code>false</code> if <code>OS_NAME</code> is
1155 * <code>null</code>.
1156 * </p>
1157 *
1158 * @since 2.1
1159 */
1160 public static final boolean IS_OS_UNIX = IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || IS_OS_MAC_OSX
1161 || IS_OS_SOLARIS || IS_OS_SUN_OS;
1162
1163 /**
1164 * <p>
1165 * Is <code>true</code> if this is Windows.
1166 * </p>
1167 * <p>
1168 * The field will return <code>false</code> if <code>OS_NAME</code> is
1169 * <code>null</code>.
1170 * </p>
1171 *
1172 * @since 2.0
1173 */
1174 public static final boolean IS_OS_WINDOWS = getOSMatches( OS_NAME_WINDOWS_PREFIX );
1175
1176 /**
1177 * <p>
1178 * Is <code>true</code> if this is Windows 2000.
1179 * </p>
1180 * <p>
1181 * The field will return <code>false</code> if <code>OS_NAME</code> is
1182 * <code>null</code>.
1183 * </p>
1184 *
1185 * @since 2.0
1186 */
1187 public static final boolean IS_OS_WINDOWS_2000 = getOSMatches( OS_NAME_WINDOWS_PREFIX, "5.0" );
1188
1189 /**
1190 * <p>
1191 * Is <code>true</code> if this is Windows 95.
1192 * </p>
1193 * <p>
1194 * The field will return <code>false</code> if <code>OS_NAME</code> is
1195 * <code>null</code>.
1196 * </p>
1197 *
1198 * @since 2.0
1199 */
1200 public static final boolean IS_OS_WINDOWS_95 = getOSMatches( OS_NAME_WINDOWS_PREFIX + " 9", "4.0" );
1201
1202 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1203
1204 /**
1205 * <p>
1206 * Is <code>true</code> if this is Windows 98.
1207 * </p>
1208 * <p>
1209 * The field will return <code>false</code> if <code>OS_NAME</code> is
1210 * <code>null</code>.
1211 * </p>
1212 *
1213 * @since 2.0
1214 */
1215 public static final boolean IS_OS_WINDOWS_98 = getOSMatches( OS_NAME_WINDOWS_PREFIX + " 9", "4.1" );
1216
1217 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above
1218
1219 /**
1220 * <p>
1221 * Is <code>true</code> if this is Windows ME.
1222 * </p>
1223 * <p>
1224 * The field will return <code>false</code> if <code>OS_NAME</code> is
1225 * <code>null</code>.
1226 * </p>
1227 *
1228 * @since 2.0
1229 */
1230 public static final boolean IS_OS_WINDOWS_ME = getOSMatches( OS_NAME_WINDOWS_PREFIX, "4.9" );
1231
1232 // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above
1233
1234 /**
1235 * <p>
1236 * Is <code>true</code> if this is Windows NT.
1237 * </p>
1238 * <p>
1239 * The field will return <code>false</code> if <code>OS_NAME</code> is
1240 * <code>null</code>.
1241 * </p>
1242 *
1243 * @since 2.0
1244 */
1245 public static final boolean IS_OS_WINDOWS_NT = getOSMatches( OS_NAME_WINDOWS_PREFIX + " NT" );
1246
1247 // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2
1248 // problem
1249
1250 /**
1251 * <p>
1252 * Is <code>true</code> if this is Windows XP.
1253 * </p>
1254 * <p>
1255 * The field will return <code>false</code> if <code>OS_NAME</code> is
1256 * <code>null</code>.
1257 * </p>
1258 *
1259 * @since 2.0
1260 */
1261 public static final boolean IS_OS_WINDOWS_XP = getOSMatches( OS_NAME_WINDOWS_PREFIX, "5.1" );
1262
1263
1264 // -----------------------------------------------------------------------
1265 /**
1266 * <p>
1267 * SystemUtils instances should NOT be constructed in standard programming.
1268 * Instead, the class should be used as
1269 * <code>SystemUtils.FILE_SEPARATOR</code>.
1270 * </p>
1271 * <p>
1272 * This constructor is public to permit tools that require a JavaBean
1273 * instance to operate.
1274 * </p>
1275 */
1276 public SystemUtils()
1277 {
1278 // no init.
1279 }
1280
1281
1282 // -----------------------------------------------------------------------
1283 /**
1284 * <p>
1285 * Gets the Java version number as a <code>float</code>.
1286 * </p>
1287 * <p>
1288 * Example return values:
1289 * </p>
1290 * <ul>
1291 * <li><code>1.2f</code> for JDK 1.2
1292 * <li><code>1.31f</code> for JDK 1.3.1
1293 * </ul>
1294 *
1295 * @return the version, for example 1.31f for JDK 1.3.1
1296 * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. Method will be
1297 * removed in Commons Lang 3.0.
1298 */
1299 public static float getJavaVersion()
1300 {
1301 return JAVA_VERSION_FLOAT;
1302 }
1303
1304
1305 /**
1306 * <p>
1307 * Gets the Java version number as a <code>float</code>.
1308 * </p>
1309 * <p>
1310 * Example return values:
1311 * </p>
1312 * <ul>
1313 * <li><code>1.2f</code> for JDK 1.2
1314 * <li><code>1.31f</code> for JDK 1.3.1
1315 * </ul>
1316 * <p>
1317 * Patch releases are not reported. Zero is returned if
1318 * {@link #JAVA_VERSION} is <code>null</code>.
1319 * </p>
1320 *
1321 * @return the version, for example 1.31f for JDK 1.3.1
1322 */
1323 private static float getJavaVersionAsFloat()
1324 {
1325 if ( JAVA_VERSION == null )
1326 {
1327 return 0f;
1328 }
1329 String str = JAVA_VERSION.substring( 0, 3 );
1330 if ( JAVA_VERSION.length() >= 5 )
1331 {
1332 str = str + JAVA_VERSION.substring( 4, 5 );
1333 }
1334 return Float.parseFloat( str );
1335 }
1336
1337
1338 /**
1339 * <p>
1340 * Gets the Java version number as an <code>int</code>.
1341 * </p>
1342 * <p>
1343 * Example return values:
1344 * </p>
1345 * <ul>
1346 * <li><code>120</code> for JDK 1.2
1347 * <li><code>131</code> for JDK 1.3.1
1348 * </ul>
1349 * <p>
1350 * Patch releases are not reported. Zero is returned if
1351 * {@link #JAVA_VERSION} is <code>null</code>.
1352 * </p>
1353 *
1354 * @return the version, for example 131 for JDK 1.3.1
1355 */
1356 private static int getJavaVersionAsInt()
1357 {
1358 if ( JAVA_VERSION == null )
1359 {
1360 return 0;
1361 }
1362 String str = JAVA_VERSION.substring( 0, 1 );
1363 str = str + JAVA_VERSION.substring( 2, 3 );
1364 if ( JAVA_VERSION.length() >= 5 )
1365 {
1366 str = str + JAVA_VERSION.substring( 4, 5 );
1367 }
1368 else
1369 {
1370 str = str + "0";
1371 }
1372 return Integer.parseInt( str );
1373 }
1374
1375
1376 /**
1377 * <p>
1378 * Decides if the java version matches.
1379 * </p>
1380 *
1381 * @param versionPrefix
1382 * the prefix for the java version
1383 * @return true if matches, or false if not or can't determine
1384 */
1385 private static boolean getJavaVersionMatches( String versionPrefix )
1386 {
1387 if ( JAVA_VERSION == null )
1388 {
1389 return false;
1390 }
1391 return JAVA_VERSION.startsWith( versionPrefix );
1392 }
1393
1394
1395 /**
1396 * <p>
1397 * Decides if the operating system matches.
1398 * </p>
1399 *
1400 * @param osNamePrefix
1401 * the prefix for the os name
1402 * @return true if matches, or false if not or can't determine
1403 */
1404 private static boolean getOSMatches( String osNamePrefix )
1405 {
1406 if ( OS_NAME == null )
1407 {
1408 return false;
1409 }
1410 return OS_NAME.startsWith( osNamePrefix );
1411 }
1412
1413
1414 /**
1415 * <p>
1416 * Decides if the operating system matches.
1417 * </p>
1418 *
1419 * @param osNamePrefix
1420 * the prefix for the os name
1421 * @param osVersionPrefix
1422 * the prefix for the version
1423 * @return true if matches, or false if not or can't determine
1424 */
1425 private static boolean getOSMatches( String osNamePrefix, String osVersionPrefix )
1426 {
1427 if ( OS_NAME == null || OS_VERSION == null )
1428 {
1429 return false;
1430 }
1431 return OS_NAME.startsWith( osNamePrefix ) && OS_VERSION.startsWith( osVersionPrefix );
1432 }
1433
1434
1435 // -----------------------------------------------------------------------
1436 /**
1437 * <p>
1438 * Gets a System property, defaulting to <code>null</code> if the property
1439 * cannot be read.
1440 * </p>
1441 * <p>
1442 * If a <code>SecurityException</code> is caught, the return value is
1443 * <code>null</code> and a message is written to <code>System.err</code>.
1444 * </p>
1445 *
1446 * @param property
1447 * the system property name
1448 * @return the system property value or <code>null</code> if a security
1449 * problem occurs
1450 */
1451 private static String getSystemProperty( String property )
1452 {
1453 try
1454 {
1455 return System.getProperty( property );
1456 }
1457 catch ( SecurityException ex )
1458 {
1459 // we are not allowed to look at this property
1460 System.err.println( "Caught a SecurityException reading the system property '" + property
1461 + "'; the SystemUtils property value will default to null." );
1462 return null;
1463 }
1464 }
1465
1466
1467 /**
1468 * <p>
1469 * Is the Java version at least the requested version.
1470 * </p>
1471 * <p>
1472 * Example input:
1473 * </p>
1474 * <ul>
1475 * <li><code>1.2f</code> to test for JDK 1.2</li>
1476 * <li><code>1.31f</code> to test for JDK 1.3.1</li>
1477 * </ul>
1478 *
1479 * @param requiredVersion
1480 * the required version, for example 1.31f
1481 * @return <code>true</code> if the actual version is equal or greater
1482 * than the required version
1483 */
1484 public static boolean isJavaVersionAtLeast( float requiredVersion )
1485 {
1486 return ( JAVA_VERSION_FLOAT >= requiredVersion );
1487 }
1488
1489
1490 /**
1491 * <p>
1492 * Is the Java version at least the requested version.
1493 * </p>
1494 * <p>
1495 * Example input:
1496 * </p>
1497 * <ul>
1498 * <li><code>120</code> to test for JDK 1.2 or greater</li>
1499 * <li><code>131</code> to test for JDK 1.3.1 or greater</li>
1500 * </ul>
1501 *
1502 * @param requiredVersion
1503 * the required version, for example 131
1504 * @return <code>true</code> if the actual version is equal or greater
1505 * than the required version
1506 * @since 2.0
1507 */
1508 public static boolean isJavaVersionAtLeast( int requiredVersion )
1509 {
1510 return ( JAVA_VERSION_INT >= requiredVersion );
1511 }
1512
1513
1514 /**
1515 * Returns whether the {@link #JAVA_AWT_HEADLESS} value is <code>true</code>.
1516 *
1517 * @return <code>true</code> if <code>JAVA_AWT_HEADLESS</code> is
1518 * <code>"true"</code>, <code>false</code> otherwise.
1519 * @see #JAVA_AWT_HEADLESS
1520 * @since 2.1
1521 * @since Java 1.4
1522 */
1523 public static boolean isJavaAwtHeadless()
1524 {
1525 return JAVA_AWT_HEADLESS != null ? JAVA_AWT_HEADLESS.equals( Boolean.TRUE.toString() ) : false;
1526 }
1527
1528
1529 /**
1530 * <p>
1531 * Gets the Java home directory as a <code>File</code>.
1532 * </p>
1533 *
1534 * @return a directory
1535 * @throws SecurityException
1536 * if a security manager exists and its
1537 * <code>checkPropertyAccess</code> method doesn't allow
1538 * access to the specified system property.
1539 * @see System#getProperty(String)
1540 */
1541 public static File getJavaHome()
1542 {
1543 return new File( System.getProperty( JAVA_HOME_KEY ) );
1544 }
1545
1546
1547 /**
1548 * <p>
1549 * Gets the Java IO temporary directory as a <code>File</code>.
1550 * </p>
1551 *
1552 * @return a directory
1553 * @throws SecurityException
1554 * if a security manager exists and its
1555 * <code>checkPropertyAccess</code> method doesn't allow
1556 * access to the specified system property.
1557 * @see System#getProperty(String)
1558 */
1559 public static File getJavaIoTmpDir()
1560 {
1561 return new File( System.getProperty( JAVA_IO_TMPDIR_KEY ) );
1562 }
1563
1564
1565 /**
1566 * <p>
1567 * Gets the user directory as a <code>File</code>.
1568 * </p>
1569 *
1570 * @return a directory
1571 * @throws SecurityException
1572 * if a security manager exists and its
1573 * <code>checkPropertyAccess</code> method doesn't allow
1574 * access to the specified system property.
1575 * @see System#getProperty(String)
1576 */
1577 public static File getUserDir()
1578 {
1579 return new File( System.getProperty( USER_DIR_KEY ) );
1580 }
1581
1582
1583 /**
1584 * <p>
1585 * Gets the user home directory as a <code>File</code>.
1586 * </p>
1587 *
1588 * @return a directory
1589 * @throws SecurityException
1590 * if a security manager exists and its
1591 * <code>checkPropertyAccess</code> method doesn't allow
1592 * access to the specified system property.
1593 * @see System#getProperty(String)
1594 */
1595 public static File getUserHome()
1596 {
1597 return new File( System.getProperty( USER_HOME_KEY ) );
1598 }
1599
1600 }