557 |
*/ |
*/ |
558 |
public static String getProperty(String key, String def) |
public static String getProperty(String key, String def) |
559 |
{ |
{ |
560 |
|
// This handles both the null pointer exception and the illegal |
561 |
|
// argument exception. |
562 |
|
if (key.equals("")) |
563 |
|
throw new IllegalArgumentException("empty key"); |
564 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
565 |
if (sm != null) |
if (sm != null) |
566 |
sm.checkPropertyAccess(key); |
sm.checkPropertyAccess(key); |
581 |
*/ |
*/ |
582 |
public static String setProperty(String key, String value) |
public static String setProperty(String key, String value) |
583 |
{ |
{ |
584 |
|
// This handles both the null pointer exception and the illegal |
585 |
|
// argument exception. |
586 |
|
if (key.equals("")) |
587 |
|
throw new IllegalArgumentException("empty key"); |
588 |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
589 |
if (sm != null) |
if (sm != null) |
590 |
sm.checkPermission(new PropertyPermission(key, "write")); |
sm.checkPermission(new PropertyPermission(key, "write")); |
592 |
} |
} |
593 |
|
|
594 |
/** |
/** |
595 |
|
* Remove a single system property by name. A security check may be |
596 |
|
* performed, <code>checkPropertyAccess(key, "write")</code>. |
597 |
|
* |
598 |
|
* @param key the name of the system property to remove |
599 |
|
* @return the previous value, or null |
600 |
|
* @throws SecurityException if permission is denied |
601 |
|
* @throws NullPointerException if key is null |
602 |
|
* @throws IllegalArgumentException if key is "" |
603 |
|
* @since 1.5 |
604 |
|
*/ |
605 |
|
public static String clearProperty(String key) |
606 |
|
{ |
607 |
|
// This handles both the null pointer exception and the illegal |
608 |
|
// argument exception. |
609 |
|
if (key.equals("")) |
610 |
|
throw new IllegalArgumentException("empty key"); |
611 |
|
SecurityManager sm = Runtime.securityManager; // Be thread-safe. |
612 |
|
if (sm != null) |
613 |
|
sm.checkPermission(new PropertyPermission(key, "write")); |
614 |
|
return (String) properties.remove(key); |
615 |
|
} |
616 |
|
|
617 |
|
/** |
618 |
* This used to get an environment variable, but following Sun's lead, |
* This used to get an environment variable, but following Sun's lead, |
619 |
* it now throws an Error. Use <code>getProperty</code> instead. |
* it now throws an Error. Use <code>getProperty</code> instead. |
620 |
* |
* |