001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.lang; 018 019 import java.io.File; 020 021 /** 022 * <p>Helpers for <code>java.lang.System</code>.</p> 023 * 024 * <p>If a system property cannot be read due to security restrictions, 025 * the corresponding field in this class will be set to <code>null</code> 026 * and a message will be written to <code>System.err</code>.</p> 027 * 028 * @author Apache Software Foundation 029 * @author Based on code from Avalon Excalibur 030 * @author Based on code from Lucene 031 * @author <a href="mailto:sdowney@panix.com">Steve Downey</a> 032 * @author Gary Gregory 033 * @author Michael Becke 034 * @author Tetsuya Kaneuchi 035 * @author Rafal Krupinski 036 * @author Jason Gritman 037 * @since 1.0 038 * @version $Id: SystemUtils.java 905707 2010-02-02 16:59:59Z niallp $ 039 */ 040 public class SystemUtils { 041 042 /** 043 * The prefix String for all Windows OS. 044 */ 045 private static final String OS_NAME_WINDOWS_PREFIX = "Windows"; 046 047 // System property constants 048 //----------------------------------------------------------------------- 049 // These MUST be declared first. Other constants depend on this. 050 051 /** 052 * The System property key for the user home directory. 053 */ 054 private static final String USER_HOME_KEY = "user.home"; 055 056 /** 057 * The System property key for the user directory. 058 */ 059 private static final String USER_DIR_KEY = "user.dir"; 060 061 /** 062 * The System property key for the Java IO temporary directory. 063 */ 064 private static final String JAVA_IO_TMPDIR_KEY = "java.io.tmpdir"; 065 066 /** 067 * The System property key for the Java home directory. 068 */ 069 private static final String JAVA_HOME_KEY = "java.home"; 070 071 /** 072 * <p>The <code>awt.toolkit</code> System Property.</p> 073 * <p>Holds a class name, on Windows XP this is <code>sun.awt.windows.WToolkit</code>.</p> 074 * <p><b>On platforms without a GUI, this value is <code>null</code>.</b></p> 075 * 076 * <p>Defaults to <code>null</code> if the runtime does not have 077 * security access to read this property or the property does not exist.</p> 078 * 079 * <p> 080 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} 081 * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value 082 * will be out of sync with that System property. 083 * </p> 084 * 085 * @since 2.1 086 */ 087 public static final String AWT_TOOLKIT = getSystemProperty("awt.toolkit"); 088 089 /** 090 * <p>The <code>file.encoding</code> System Property.</p> 091 * <p>File encoding, such as <code>Cp1252</code>.</p> 092 * 093 * <p>Defaults to <code>null</code> if the runtime does not have 094 * security access to read this property or the property does not exist.</p> 095 * 096 * <p> 097 * This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} 098 * or {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value 099 * 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>"/"</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>"\n"</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>":"</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 /** 889 * <p>Is <code>true</code> if this is Java version 1.7 (also 1.7.x versions).</p> 890 * 891 * <p>The field will return <code>false</code> if {@link #JAVA_VERSION} is 892 * <code>null</code>.</p> 893 * 894 * @since 2.5 895 */ 896 public static final boolean IS_JAVA_1_7 = getJavaVersionMatches("1.7"); 897 898 // Operating system checks 899 //----------------------------------------------------------------------- 900 // These MUST be declared after those above as they depend on the 901 // values being set up 902 // OS names from http://www.vamphq.com/os.html 903 // Selected ones included - please advise dev@commons.apache.org 904 // if you want another added or a mistake corrected 905 906 /** 907 * <p>Is <code>true</code> if this is AIX.</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_AIX = getOSMatches("AIX"); 915 916 /** 917 * <p>Is <code>true</code> if this is HP-UX.</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_HP_UX = getOSMatches("HP-UX"); 925 926 /** 927 * <p>Is <code>true</code> if this is Irix.</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_IRIX = getOSMatches("Irix"); 935 936 /** 937 * <p>Is <code>true</code> if this is Linux.</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_LINUX = getOSMatches("Linux") || getOSMatches("LINUX"); 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 = getOSMatches("Mac"); 955 956 /** 957 * <p>Is <code>true</code> if this is Mac.</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_MAC_OSX = getOSMatches("Mac OS X"); 965 966 /** 967 * <p>Is <code>true</code> if this is OS/2.</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_OS2 = getOSMatches("OS/2"); 975 976 /** 977 * <p>Is <code>true</code> if this is Solaris.</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_SOLARIS = getOSMatches("Solaris"); 985 986 /** 987 * <p>Is <code>true</code> if this is SunOS.</p> 988 * 989 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 990 * <code>null</code>.</p> 991 * 992 * @since 2.0 993 */ 994 public static final boolean IS_OS_SUN_OS = getOSMatches("SunOS"); 995 996 /** 997 * <p>Is <code>true</code> if this is a POSIX compilant system, 998 * as in any of AIX, HP-UX, Irix, Linux, MacOSX, Solaris or SUN OS.</p> 999 * 1000 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1001 * <code>null</code>.</p> 1002 * 1003 * @since 2.1 1004 */ 1005 public static final boolean IS_OS_UNIX = 1006 IS_OS_AIX || IS_OS_HP_UX || IS_OS_IRIX || IS_OS_LINUX || 1007 IS_OS_MAC_OSX || IS_OS_SOLARIS || IS_OS_SUN_OS; 1008 1009 /** 1010 * <p>Is <code>true</code> if this is Windows.</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 = getOSMatches(OS_NAME_WINDOWS_PREFIX); 1018 1019 /** 1020 * <p>Is <code>true</code> if this is Windows 2000.</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_2000 = getOSMatches(OS_NAME_WINDOWS_PREFIX, "5.0"); 1028 1029 /** 1030 * <p>Is <code>true</code> if this is Windows 95.</p> 1031 * 1032 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1033 * <code>null</code>.</p> 1034 * 1035 * @since 2.0 1036 */ 1037 public static final boolean IS_OS_WINDOWS_95 = getOSMatches(OS_NAME_WINDOWS_PREFIX + " 9", "4.0"); 1038 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above 1039 1040 /** 1041 * <p>Is <code>true</code> if this is Windows 98.</p> 1042 * 1043 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1044 * <code>null</code>.</p> 1045 * 1046 * @since 2.0 1047 */ 1048 public static final boolean IS_OS_WINDOWS_98 = getOSMatches(OS_NAME_WINDOWS_PREFIX + " 9", "4.1"); 1049 // JDK 1.2 running on Windows98 returns 'Windows 95', hence the above 1050 1051 /** 1052 * <p>Is <code>true</code> if this is Windows ME.</p> 1053 * 1054 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1055 * <code>null</code>.</p> 1056 * 1057 * @since 2.0 1058 */ 1059 public static final boolean IS_OS_WINDOWS_ME = getOSMatches(OS_NAME_WINDOWS_PREFIX, "4.9"); 1060 // JDK 1.2 running on WindowsME may return 'Windows 95', hence the above 1061 1062 /** 1063 * <p>Is <code>true</code> if this is Windows NT.</p> 1064 * 1065 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1066 * <code>null</code>.</p> 1067 * 1068 * @since 2.0 1069 */ 1070 public static final boolean IS_OS_WINDOWS_NT = getOSMatches(OS_NAME_WINDOWS_PREFIX + " NT"); 1071 // Windows 2000 returns 'Windows 2000' but may suffer from same JDK1.2 problem 1072 1073 /** 1074 * <p>Is <code>true</code> if this is Windows XP.</p> 1075 * 1076 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1077 * <code>null</code>.</p> 1078 * 1079 * @since 2.0 1080 */ 1081 public static final boolean IS_OS_WINDOWS_XP = getOSMatches(OS_NAME_WINDOWS_PREFIX, "5.1"); 1082 1083 //----------------------------------------------------------------------- 1084 /** 1085 * <p>Is <code>true</code> if this is Windows Vista.</p> 1086 * 1087 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1088 * <code>null</code>.</p> 1089 * 1090 * @since 2.4 1091 */ 1092 public static final boolean IS_OS_WINDOWS_VISTA = getOSMatches(OS_NAME_WINDOWS_PREFIX, "6.0"); 1093 1094 /** 1095 * <p>Is <code>true</code> if this is Windows 7.</p> 1096 * 1097 * <p>The field will return <code>false</code> if <code>OS_NAME</code> is 1098 * <code>null</code>.</p> 1099 * 1100 * @since 2.5 1101 */ 1102 public static final boolean IS_OS_WINDOWS_7 = getOSMatches(OS_NAME_WINDOWS_PREFIX, "6.1"); 1103 1104 //----------------------------------------------------------------------- 1105 /** 1106 * <p>SystemUtils instances should NOT be constructed in standard 1107 * programming. Instead, the class should be used as 1108 * <code>SystemUtils.FILE_SEPARATOR</code>.</p> 1109 * 1110 * <p>This constructor is public to permit tools that require a JavaBean 1111 * instance to operate.</p> 1112 */ 1113 public SystemUtils() { 1114 super(); 1115 } 1116 1117 //----------------------------------------------------------------------- 1118 /** 1119 * <p>Gets the Java version number as a <code>float</code>.</p> 1120 * 1121 * <p>Example return values:</p> 1122 * <ul> 1123 * <li><code>1.2f</code> for JDK 1.2 1124 * <li><code>1.31f</code> for JDK 1.3.1 1125 * </ul> 1126 * 1127 * @return the version, for example 1.31f for JDK 1.3.1 1128 * @deprecated Use {@link #JAVA_VERSION_FLOAT} instead. 1129 * Method will be removed in Commons Lang 3.0. 1130 */ 1131 public static float getJavaVersion() { 1132 return JAVA_VERSION_FLOAT; 1133 } 1134 1135 /** 1136 * <p>Gets the Java version number as a <code>float</code>.</p> 1137 * 1138 * <p>Example return values:</p> 1139 * <ul> 1140 * <li><code>1.2f</code> for JDK 1.2 1141 * <li><code>1.31f</code> for JDK 1.3.1 1142 * </ul> 1143 * 1144 * <p>Patch releases are not reported. 1145 * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p> 1146 * 1147 * @return the version, for example 1.31f for JDK 1.3.1 1148 */ 1149 private static float getJavaVersionAsFloat() { 1150 if (JAVA_VERSION_TRIMMED == null) { 1151 return 0f; 1152 } 1153 String str = JAVA_VERSION_TRIMMED.substring(0, 3); 1154 if (JAVA_VERSION_TRIMMED.length() >= 5) { 1155 str = str + JAVA_VERSION_TRIMMED.substring(4, 5); 1156 } 1157 try { 1158 return Float.parseFloat(str); 1159 } catch (Exception ex) { 1160 return 0; 1161 } 1162 } 1163 1164 /** 1165 * <p>Gets the Java version number as an <code>int</code>.</p> 1166 * 1167 * <p>Example return values:</p> 1168 * <ul> 1169 * <li><code>120</code> for JDK 1.2 1170 * <li><code>131</code> for JDK 1.3.1 1171 * </ul> 1172 * 1173 * <p>Patch releases are not reported. 1174 * Zero is returned if {@link #JAVA_VERSION_TRIMMED} is <code>null</code>.</p> 1175 * 1176 * @return the version, for example 131 for JDK 1.3.1 1177 */ 1178 private static int getJavaVersionAsInt() { 1179 if (JAVA_VERSION_TRIMMED == null) { 1180 return 0; 1181 } 1182 String str = JAVA_VERSION_TRIMMED.substring(0, 1); 1183 str = str + JAVA_VERSION_TRIMMED.substring(2, 3); 1184 if (JAVA_VERSION_TRIMMED.length() >= 5) { 1185 str = str + JAVA_VERSION_TRIMMED.substring(4, 5); 1186 } else { 1187 str = str + "0"; 1188 } 1189 try { 1190 return Integer.parseInt(str); 1191 } catch (Exception ex) { 1192 return 0; 1193 } 1194 } 1195 1196 /** 1197 * Trims the text of the java version to start with numbers. 1198 * 1199 * @return the trimmed java version 1200 */ 1201 private static String getJavaVersionTrimmed() { 1202 if (JAVA_VERSION != null) { 1203 for (int i = 0; i < JAVA_VERSION.length(); i++) { 1204 char ch = JAVA_VERSION.charAt(i); 1205 if (ch >= '0' && ch <= '9') { 1206 return JAVA_VERSION.substring(i); 1207 } 1208 } 1209 } 1210 return null; 1211 } 1212 1213 /** 1214 * <p>Decides if the java version matches.</p> 1215 * 1216 * @param versionPrefix the prefix for the java version 1217 * @return true if matches, or false if not or can't determine 1218 */ 1219 private static boolean getJavaVersionMatches(String versionPrefix) { 1220 if (JAVA_VERSION_TRIMMED == null) { 1221 return false; 1222 } 1223 return JAVA_VERSION_TRIMMED.startsWith(versionPrefix); 1224 } 1225 1226 /** 1227 * <p>Decides if the operating system matches.</p> 1228 * 1229 * @param osNamePrefix the prefix for the os name 1230 * @return true if matches, or false if not or can't determine 1231 */ 1232 private static boolean getOSMatches(String osNamePrefix) { 1233 if (OS_NAME == null) { 1234 return false; 1235 } 1236 return OS_NAME.startsWith(osNamePrefix); 1237 } 1238 1239 /** 1240 * <p>Decides if the operating system matches.</p> 1241 * 1242 * @param osNamePrefix the prefix for the os name 1243 * @param osVersionPrefix the prefix for the version 1244 * @return true if matches, or false if not or can't determine 1245 */ 1246 private static boolean getOSMatches(String osNamePrefix, String osVersionPrefix) { 1247 if (OS_NAME == null || OS_VERSION == null) { 1248 return false; 1249 } 1250 return OS_NAME.startsWith(osNamePrefix) && OS_VERSION.startsWith(osVersionPrefix); 1251 } 1252 1253 //----------------------------------------------------------------------- 1254 /** 1255 * <p>Gets a System property, defaulting to <code>null</code> if the property 1256 * cannot be read.</p> 1257 * 1258 * <p>If a <code>SecurityException</code> is caught, the return 1259 * value is <code>null</code> and a message is written to <code>System.err</code>.</p> 1260 * 1261 * @param property the system property name 1262 * @return the system property value or <code>null</code> if a security problem occurs 1263 */ 1264 private static String getSystemProperty(String property) { 1265 try { 1266 return System.getProperty(property); 1267 } catch (SecurityException ex) { 1268 // we are not allowed to look at this property 1269 System.err.println( 1270 "Caught a SecurityException reading the system property '" + property 1271 + "'; the SystemUtils property value will default to null." 1272 ); 1273 return null; 1274 } 1275 } 1276 1277 /** 1278 * <p>Is the Java version at least the requested version.</p> 1279 * 1280 * <p>Example input:</p> 1281 * <ul> 1282 * <li><code>1.2f</code> to test for JDK 1.2</li> 1283 * <li><code>1.31f</code> to test for JDK 1.3.1</li> 1284 * </ul> 1285 * 1286 * @param requiredVersion the required version, for example 1.31f 1287 * @return <code>true</code> if the actual version is equal or greater 1288 * than the required version 1289 */ 1290 public static boolean isJavaVersionAtLeast(float requiredVersion) { 1291 return JAVA_VERSION_FLOAT >= requiredVersion; 1292 } 1293 1294 /** 1295 * <p>Is the Java version at least the requested version.</p> 1296 * 1297 * <p>Example input:</p> 1298 * <ul> 1299 * <li><code>120</code> to test for JDK 1.2 or greater</li> 1300 * <li><code>131</code> to test for JDK 1.3.1 or greater</li> 1301 * </ul> 1302 * 1303 * @param requiredVersion the required version, for example 131 1304 * @return <code>true</code> if the actual version is equal or greater 1305 * than the required version 1306 * @since 2.0 1307 */ 1308 public static boolean isJavaVersionAtLeast(int requiredVersion) { 1309 return JAVA_VERSION_INT >= requiredVersion; 1310 } 1311 1312 /** 1313 * Returns whether the {@link #JAVA_AWT_HEADLESS} value is <code>true</code>. 1314 * 1315 * @return <code>true</code> if <code>JAVA_AWT_HEADLESS</code> is <code>"true"</code>, 1316 * <code>false</code> otherwise. 1317 * 1318 * @see #JAVA_AWT_HEADLESS 1319 * @since 2.1 1320 * @since Java 1.4 1321 */ 1322 public static boolean isJavaAwtHeadless() { 1323 return JAVA_AWT_HEADLESS != null ? JAVA_AWT_HEADLESS.equals(Boolean.TRUE.toString()) : false; 1324 } 1325 /** 1326 * <p>Gets the Java home directory as a <code>File</code>.</p> 1327 * 1328 * @return a directory 1329 * @throws SecurityException if a security manager exists and its 1330 * <code>checkPropertyAccess</code> method doesn't allow 1331 * access to the specified system property. 1332 * @see System#getProperty(String) 1333 * @since 2.1 1334 */ 1335 public static File getJavaHome() { 1336 return new File(System.getProperty(JAVA_HOME_KEY)); 1337 } 1338 1339 /** 1340 * <p>Gets the Java IO temporary directory as a <code>File</code>.</p> 1341 * 1342 * @return a directory 1343 * @throws SecurityException if a security manager exists and its 1344 * <code>checkPropertyAccess</code> method doesn't allow 1345 * access to the specified system property. 1346 * @see System#getProperty(String) 1347 * @since 2.1 1348 */ 1349 public static File getJavaIoTmpDir() { 1350 return new File(System.getProperty(JAVA_IO_TMPDIR_KEY)); 1351 } 1352 1353 /** 1354 * <p>Gets the user directory as a <code>File</code>.</p> 1355 * 1356 * @return a directory 1357 * @throws SecurityException if a security manager exists and its 1358 * <code>checkPropertyAccess</code> method doesn't allow 1359 * access to the specified system property. 1360 * @see System#getProperty(String) 1361 * @since 2.1 1362 */ 1363 public static File getUserDir() { 1364 return new File(System.getProperty(USER_DIR_KEY)); 1365 } 1366 1367 /** 1368 * <p>Gets the user home directory as a <code>File</code>.</p> 1369 * 1370 * @return a directory 1371 * @throws SecurityException if a security manager exists and its 1372 * <code>checkPropertyAccess</code> method doesn't allow 1373 * access to the specified system property. 1374 * @see System#getProperty(String) 1375 * @since 2.1 1376 */ 1377 public static File getUserHome() { 1378 return new File(System.getProperty(USER_HOME_KEY)); 1379 } 1380 1381 }