116 * Typically this stream corresponds to display output or another
117 * output destination specified by the host environment or user. By
118 * convention, this output stream is used to display error messages
119 * or other information that should come to the immediate attention
120 * of a user even if the principal output stream, the value of the
121 * variable <code>out</code>, has been redirected to a file or other
122 * destination that is typically not continuously monitored.
123 */
124 public final static PrintStream err = null;
125
126 /* The security manager for the system.
127 */
128 private static volatile SecurityManager security = null;
129
130 /**
131 * Reassigns the "standard" input stream.
132 *
133 * <p>First, if there is a security manager, its <code>checkPermission</code>
134 * method is called with a <code>RuntimePermission("setIO")</code> permission
135 * to see if it's ok to reassign the "standard" input stream.
136 * <p>
137 *
138 * @param in the new standard input stream.
139 *
140 * @throws SecurityException
141 * if a security manager exists and its
142 * <code>checkPermission</code> method doesn't allow
143 * reassigning of the standard input stream.
144 *
145 * @see SecurityManager#checkPermission
146 * @see java.lang.RuntimePermission
147 *
148 * @since JDK1.1
149 */
150 public static void setIn(InputStream in) {
151 checkIO();
152 setIn0(in);
153 }
154
155 /**
156 * Reassigns the "standard" output stream.
745 */
746 public static String getProperty(String key, String def) {
747 checkKey(key);
748 SecurityManager sm = getSecurityManager();
749 if (sm != null) {
750 sm.checkPropertyAccess(key);
751 }
752
753 return props.getProperty(key, def);
754 }
755
756 /**
757 * Sets the system property indicated by the specified key.
758 * <p>
759 * First, if a security manager exists, its
760 * <code>SecurityManager.checkPermission</code> method
761 * is called with a <code>PropertyPermission(key, "write")</code>
762 * permission. This may result in a SecurityException being thrown.
763 * If no exception is thrown, the specified property is set to the given
764 * value.
765 * <p>
766 *
767 * @param key the name of the system property.
768 * @param value the value of the system property.
769 * @return the previous value of the system property,
770 * or <code>null</code> if it did not have one.
771 *
772 * @exception SecurityException if a security manager exists and its
773 * <code>checkPermission</code> method doesn't allow
774 * setting of the specified property.
775 * @exception NullPointerException if <code>key</code> or
776 * <code>value</code> is <code>null</code>.
777 * @exception IllegalArgumentException if <code>key</code> is empty.
778 * @see #getProperty
779 * @see java.lang.System#getProperty(java.lang.String)
780 * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
781 * @see java.util.PropertyPermission
782 * @see SecurityManager#checkPermission
783 * @since 1.2
784 */
785 public static String setProperty(String key, String value) {
786 checkKey(key);
787 SecurityManager sm = getSecurityManager();
788 if (sm != null) {
789 sm.checkPermission(new PropertyPermission(key,
790 SecurityConstants.PROPERTY_WRITE_ACTION));
791 }
792
793 return (String) props.setProperty(key, value);
794 }
795
796 /**
797 * Removes the system property indicated by the specified key.
798 * <p>
799 * First, if a security manager exists, its
800 * <code>SecurityManager.checkPermission</code> method
801 * is called with a <code>PropertyPermission(key, "write")</code>
802 * permission. This may result in a SecurityException being thrown.
803 * If no exception is thrown, the specified property is removed.
804 * <p>
805 *
806 * @param key the name of the system property to be removed.
807 * @return the previous string value of the system property,
808 * or <code>null</code> if there was no property with that key.
809 *
810 * @exception SecurityException if a security manager exists and its
811 * <code>checkPropertyAccess</code> method doesn't allow
812 * access to the specified system property.
813 * @exception NullPointerException if <code>key</code> is
814 * <code>null</code>.
815 * @exception IllegalArgumentException if <code>key</code> is empty.
816 * @see #getProperty
817 * @see #setProperty
818 * @see java.util.Properties
819 * @see java.lang.SecurityException
820 * @see java.lang.SecurityManager#checkPropertiesAccess()
821 * @since 1.5
822 */
823 public static String clearProperty(String key) {
824 checkKey(key);
|
116 * Typically this stream corresponds to display output or another
117 * output destination specified by the host environment or user. By
118 * convention, this output stream is used to display error messages
119 * or other information that should come to the immediate attention
120 * of a user even if the principal output stream, the value of the
121 * variable <code>out</code>, has been redirected to a file or other
122 * destination that is typically not continuously monitored.
123 */
124 public final static PrintStream err = null;
125
126 /* The security manager for the system.
127 */
128 private static volatile SecurityManager security = null;
129
130 /**
131 * Reassigns the "standard" input stream.
132 *
133 * <p>First, if there is a security manager, its <code>checkPermission</code>
134 * method is called with a <code>RuntimePermission("setIO")</code> permission
135 * to see if it's ok to reassign the "standard" input stream.
136 *
137 * @param in the new standard input stream.
138 *
139 * @throws SecurityException
140 * if a security manager exists and its
141 * <code>checkPermission</code> method doesn't allow
142 * reassigning of the standard input stream.
143 *
144 * @see SecurityManager#checkPermission
145 * @see java.lang.RuntimePermission
146 *
147 * @since JDK1.1
148 */
149 public static void setIn(InputStream in) {
150 checkIO();
151 setIn0(in);
152 }
153
154 /**
155 * Reassigns the "standard" output stream.
744 */
745 public static String getProperty(String key, String def) {
746 checkKey(key);
747 SecurityManager sm = getSecurityManager();
748 if (sm != null) {
749 sm.checkPropertyAccess(key);
750 }
751
752 return props.getProperty(key, def);
753 }
754
755 /**
756 * Sets the system property indicated by the specified key.
757 * <p>
758 * First, if a security manager exists, its
759 * <code>SecurityManager.checkPermission</code> method
760 * is called with a <code>PropertyPermission(key, "write")</code>
761 * permission. This may result in a SecurityException being thrown.
762 * If no exception is thrown, the specified property is set to the given
763 * value.
764 *
765 * @param key the name of the system property.
766 * @param value the value of the system property.
767 * @return the previous value of the system property,
768 * or <code>null</code> if it did not have one.
769 *
770 * @exception SecurityException if a security manager exists and its
771 * <code>checkPermission</code> method doesn't allow
772 * setting of the specified property.
773 * @exception NullPointerException if <code>key</code> or
774 * <code>value</code> is <code>null</code>.
775 * @exception IllegalArgumentException if <code>key</code> is empty.
776 * @see #getProperty
777 * @see java.lang.System#getProperty(java.lang.String)
778 * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
779 * @see java.util.PropertyPermission
780 * @see SecurityManager#checkPermission
781 * @since 1.2
782 */
783 public static String setProperty(String key, String value) {
784 checkKey(key);
785 SecurityManager sm = getSecurityManager();
786 if (sm != null) {
787 sm.checkPermission(new PropertyPermission(key,
788 SecurityConstants.PROPERTY_WRITE_ACTION));
789 }
790
791 return (String) props.setProperty(key, value);
792 }
793
794 /**
795 * Removes the system property indicated by the specified key.
796 * <p>
797 * First, if a security manager exists, its
798 * <code>SecurityManager.checkPermission</code> method
799 * is called with a <code>PropertyPermission(key, "write")</code>
800 * permission. This may result in a SecurityException being thrown.
801 * If no exception is thrown, the specified property is removed.
802 *
803 * @param key the name of the system property to be removed.
804 * @return the previous string value of the system property,
805 * or <code>null</code> if there was no property with that key.
806 *
807 * @exception SecurityException if a security manager exists and its
808 * <code>checkPropertyAccess</code> method doesn't allow
809 * access to the specified system property.
810 * @exception NullPointerException if <code>key</code> is
811 * <code>null</code>.
812 * @exception IllegalArgumentException if <code>key</code> is empty.
813 * @see #getProperty
814 * @see #setProperty
815 * @see java.util.Properties
816 * @see java.lang.SecurityException
817 * @see java.lang.SecurityManager#checkPropertiesAccess()
818 * @since 1.5
819 */
820 public static String clearProperty(String key) {
821 checkKey(key);
|