43 * or loaded from a stream. Each key and its corresponding value in
44 * the property list is a string.
45 * <p>
46 * A property list can contain another property list as its
47 * "defaults"; this second property list is searched if
48 * the property key is not found in the original property list.
49 * <p>
50 * Because {@code Properties} inherits from {@code Hashtable}, the
51 * {@code put} and {@code putAll} methods can be applied to a
52 * {@code Properties} object. Their use is strongly discouraged as they
53 * allow the caller to insert entries whose keys or values are not
54 * {@code Strings}. The {@code setProperty} method should be used
55 * instead. If the {@code store} or {@code save} method is called
56 * on a "compromised" {@code Properties} object that contains a
57 * non-{@code String} key or value, the call will fail. Similarly,
58 * the call to the {@code propertyNames} or {@code list} method
59 * will fail if it is called on a "compromised" {@code Properties}
60 * object that contains a non-{@code String} key.
61 *
62 * <p>
63 * The {@link #load(java.io.Reader) load(Reader)} <tt>/</tt>
64 * {@link #store(java.io.Writer, java.lang.String) store(Writer, String)}
65 * methods load and store properties from and to a character based stream
66 * in a simple line-oriented format specified below.
67 *
68 * The {@link #load(java.io.InputStream) load(InputStream)} <tt>/</tt>
69 * {@link #store(java.io.OutputStream, java.lang.String) store(OutputStream, String)}
70 * methods work the same way as the load(Reader)/store(Writer, String) pair, except
71 * the input/output stream is encoded in ISO 8859-1 character encoding.
72 * Characters that cannot be directly represented in this encoding can be written using
73 * Unicode escapes as defined in section 3.3 of
74 * <cite>The Java™ Language Specification</cite>;
75 * only a single 'u' character is allowed in an escape
76 * sequence.
77 *
78 * <p> The {@link #loadFromXML(InputStream)} and {@link
79 * #storeToXML(OutputStream, String, String)} methods load and store properties
80 * in a simple XML format. By default the UTF-8 character encoding is used,
81 * however a specific encoding may be specified if required. Implementations
82 * are required to support UTF-8 and UTF-16 and may support other encodings.
83 * An XML properties document has the following DOCTYPE declaration:
84 *
85 * <pre>
86 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
87 * </pre>
88 * Note that the system URI (http://java.sun.com/dtd/properties.dtd) is
89 * <i>not</i> accessed when exporting or importing properties; it merely
90 * serves as a string to uniquely identify the DTD, which is:
91 * <pre>
92 * <?xml version="1.0" encoding="UTF-8"?>
93 *
94 * <!-- DTD for properties -->
95 *
96 * <!ELEMENT properties ( comment?, entry* ) >
97 *
98 * <!ATTLIST properties version CDATA #FIXED "1.0">
99 *
100 * <!ELEMENT comment (#PCDATA) >
101 *
102 * <!ELEMENT entry (#PCDATA) >
103 *
104 * <!ATTLIST entry key CDATA #REQUIRED>
105 * </pre>
106 *
107 * <p>This class is thread-safe: multiple threads can share a single
108 * <tt>Properties</tt> object without the need for external synchronization.
109 *
110 * @author Arthur van Hoff
111 * @author Michael McCloskey
112 * @author Xueming Shen
113 * @since 1.0
114 */
115 public
116 class Properties extends Hashtable<Object,Object> {
117 /**
118 * use serialVersionUID from JDK 1.1.X for interoperability
119 */
120 private static final long serialVersionUID = 4112578634029874840L;
121
122 /**
123 * A property list that contains default values for any keys not
124 * found in this property list.
125 *
126 * @serial
127 */
128 protected Properties defaults;
129
130 /**
131 * Creates an empty property list with no default values.
132 */
133 public Properties() {
134 this(null);
135 }
136
137 /**
138 * Creates an empty property list with the specified defaults.
139 *
140 * @param defaults the defaults.
141 */
142 public Properties(Properties defaults) {
143 this.defaults = defaults;
144 }
145
146 /**
147 * Calls the <tt>Hashtable</tt> method {@code put}. Provided for
148 * parallelism with the <tt>getProperty</tt> method. Enforces use of
149 * strings for property keys and values. The value returned is the
150 * result of the <tt>Hashtable</tt> call to {@code put}.
151 *
152 * @param key the key to be placed into this property list.
153 * @param value the value corresponding to <tt>key</tt>.
154 * @return the previous value of the specified key in this property
155 * list, or {@code null} if it did not have one.
156 * @see #getProperty
157 * @since 1.2
158 */
159 public synchronized Object setProperty(String key, String value) {
160 return put(key, value);
161 }
162
163
164 /**
165 * Reads a property list (key and element pairs) from the input
166 * character stream in a simple line-oriented format.
167 * <p>
168 * Properties are processed in terms of lines. There are two
169 * kinds of line, <i>natural lines</i> and <i>logical lines</i>.
170 * A natural line is defined as a line of
171 * characters that is terminated either by a set of line terminator
172 * characters ({@code \n} or {@code \r} or {@code \r\n})
173 * or by the end of the stream. A natural line may be either a blank line,
739 * by the {@code toString} method of {@code Date} for the
740 * current time), and a line separator as generated by the {@code Writer}.
741 * <p>
742 * Then every entry in this {@code Properties} table is
743 * written out, one per line. For each entry the key string is
744 * written, then an ASCII {@code =}, then the associated
745 * element string. For the key, all space characters are
746 * written with a preceding {@code \} character. For the
747 * element, leading space characters, but not embedded or trailing
748 * space characters, are written with a preceding {@code \}
749 * character. The key and element characters {@code #},
750 * {@code !}, {@code =}, and {@code :} are written
751 * with a preceding backslash to ensure that they are properly loaded.
752 * <p>
753 * After the entries have been written, the output stream is flushed.
754 * The output stream remains open after this method returns.
755 *
756 * @param writer an output character stream writer.
757 * @param comments a description of the property list.
758 * @exception IOException if writing this property list to the specified
759 * output stream throws an <tt>IOException</tt>.
760 * @exception ClassCastException if this {@code Properties} object
761 * contains any keys or values that are not {@code Strings}.
762 * @exception NullPointerException if {@code writer} is null.
763 * @since 1.6
764 */
765 public void store(Writer writer, String comments)
766 throws IOException
767 {
768 store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
769 : new BufferedWriter(writer),
770 comments,
771 false);
772 }
773
774 /**
775 * Writes this property list (key and element pairs) in this
776 * {@code Properties} table to the output stream in a format suitable
777 * for loading into a {@code Properties} table using the
778 * {@link #load(InputStream) load(InputStream)} method.
779 * <p>
786 * with the following differences:
787 * <ul>
788 * <li>The stream is written using the ISO 8859-1 character encoding.
789 *
790 * <li>Characters not in Latin-1 in the comments are written as
791 * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
792 * hexadecimal value <i>xxxx</i>.
793 *
794 * <li>Characters less than {@code \u005Cu0020} and characters greater
795 * than {@code \u005Cu007E} in property keys or values are written
796 * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
797 * value <i>xxxx</i>.
798 * </ul>
799 * <p>
800 * After the entries have been written, the output stream is flushed.
801 * The output stream remains open after this method returns.
802 *
803 * @param out an output stream.
804 * @param comments a description of the property list.
805 * @exception IOException if writing this property list to the specified
806 * output stream throws an <tt>IOException</tt>.
807 * @exception ClassCastException if this {@code Properties} object
808 * contains any keys or values that are not {@code Strings}.
809 * @exception NullPointerException if {@code out} is null.
810 * @since 1.2
811 */
812 public void store(OutputStream out, String comments)
813 throws IOException
814 {
815 store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
816 comments,
817 true);
818 }
819
820 private void store0(BufferedWriter bw, String comments, boolean escUnicode)
821 throws IOException
822 {
823 if (comments != null) {
824 writeComments(bw, comments);
825 }
826 bw.write("#" + new Date().toString());
843
844 /**
845 * Loads all of the properties represented by the XML document on the
846 * specified input stream into this properties table.
847 *
848 * <p>The XML document must have the following DOCTYPE declaration:
849 * <pre>
850 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
851 * </pre>
852 * Furthermore, the document must satisfy the properties DTD described
853 * above.
854 *
855 * <p> An implementation is required to read XML documents that use the
856 * "{@code UTF-8}" or "{@code UTF-16}" encoding. An implementation may
857 * support additional encodings.
858 *
859 * <p>The specified stream is closed after this method returns.
860 *
861 * @param in the input stream from which to read the XML document.
862 * @throws IOException if reading from the specified input stream
863 * results in an <tt>IOException</tt>.
864 * @throws java.io.UnsupportedEncodingException if the document's encoding
865 * declaration can be read and it specifies an encoding that is not
866 * supported
867 * @throws InvalidPropertiesFormatException Data on input stream does not
868 * constitute a valid XML document with the mandated document type.
869 * @throws NullPointerException if {@code in} is null.
870 * @see #storeToXML(OutputStream, String, String)
871 * @see <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
872 * Encoding in Entities</a>
873 * @since 1.5
874 */
875 public synchronized void loadFromXML(InputStream in)
876 throws IOException, InvalidPropertiesFormatException
877 {
878 Objects.requireNonNull(in);
879 PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
880 handler.load(this, in);
881 in.close();
882 }
883
884 /**
885 * Emits an XML document representing all of the properties contained
886 * in this table.
887 *
888 * <p> An invocation of this method of the form <tt>props.storeToXML(os,
889 * comment)</tt> behaves in exactly the same way as the invocation
890 * <tt>props.storeToXML(os, comment, "UTF-8");</tt>.
891 *
892 * @param os the output stream on which to emit the XML document.
893 * @param comment a description of the property list, or {@code null}
894 * if no comment is desired.
895 * @throws IOException if writing to the specified output stream
896 * results in an <tt>IOException</tt>.
897 * @throws NullPointerException if {@code os} is null.
898 * @throws ClassCastException if this {@code Properties} object
899 * contains any keys or values that are not
900 * {@code Strings}.
901 * @see #loadFromXML(InputStream)
902 * @since 1.5
903 */
904 public void storeToXML(OutputStream os, String comment)
905 throws IOException
906 {
907 storeToXML(os, comment, "UTF-8");
908 }
909
910 /**
911 * Emits an XML document representing all of the properties contained
912 * in this table, using the specified encoding.
913 *
914 * <p>The XML document will have the following DOCTYPE declaration:
915 * <pre>
916 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
917 * </pre>
918 *
919 * <p>If the specified comment is {@code null} then no comment
920 * will be stored in the document.
921 *
922 * <p> An implementation is required to support writing of XML documents
923 * that use the "{@code UTF-8}" or "{@code UTF-16}" encoding. An
924 * implementation may support additional encodings.
925 *
926 * <p>The specified stream remains open after this method returns.
927 *
928 * @param os the output stream on which to emit the XML document.
929 * @param comment a description of the property list, or {@code null}
930 * if no comment is desired.
931 * @param encoding the name of a supported
932 * <a href="../lang/package-summary.html#charenc">
933 * character encoding</a>
934 *
935 * @throws IOException if writing to the specified output stream
936 * results in an <tt>IOException</tt>.
937 * @throws java.io.UnsupportedEncodingException if the encoding is not
938 * supported by the implementation.
939 * @throws NullPointerException if {@code os} is {@code null},
940 * or if {@code encoding} is {@code null}.
941 * @throws ClassCastException if this {@code Properties} object
942 * contains any keys or values that are not
943 * {@code Strings}.
944 * @see #loadFromXML(InputStream)
945 * @see <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
946 * Encoding in Entities</a>
947 * @since 1.5
948 */
949 public void storeToXML(OutputStream os, String comment, String encoding)
950 throws IOException
951 {
952 Objects.requireNonNull(os);
953 Objects.requireNonNull(encoding);
954 PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
955 handler.store(this, os, comment, encoding);
956 }
999 * @return an enumeration of all the keys in this property list, including
1000 * the keys in the default property list.
1001 * @throws ClassCastException if any key in this property list
1002 * is not a string.
1003 * @see java.util.Enumeration
1004 * @see java.util.Properties#defaults
1005 * @see #stringPropertyNames
1006 */
1007 public Enumeration<?> propertyNames() {
1008 Hashtable<String,Object> h = new Hashtable<>();
1009 enumerate(h);
1010 return h.keys();
1011 }
1012
1013 /**
1014 * Returns a set of keys in this property list where
1015 * the key and its corresponding value are strings,
1016 * including distinct keys in the default property list if a key
1017 * of the same name has not already been found from the main
1018 * properties list. Properties whose key or value is not
1019 * of type <tt>String</tt> are omitted.
1020 * <p>
1021 * The returned set is not backed by the <tt>Properties</tt> object.
1022 * Changes to this <tt>Properties</tt> are not reflected in the set,
1023 * or vice versa.
1024 *
1025 * @return a set of keys in this property list where
1026 * the key and its corresponding value are strings,
1027 * including the keys in the default property list.
1028 * @see java.util.Properties#defaults
1029 * @since 1.6
1030 */
1031 public Set<String> stringPropertyNames() {
1032 Hashtable<String, String> h = new Hashtable<>();
1033 enumerateStringProperties(h);
1034 return h.keySet();
1035 }
1036
1037 /**
1038 * Prints this property list out to the specified output stream.
1039 * This method is useful for debugging.
1040 *
1041 * @param out an output stream.
1042 * @throws ClassCastException if any key in this property list
|
43 * or loaded from a stream. Each key and its corresponding value in
44 * the property list is a string.
45 * <p>
46 * A property list can contain another property list as its
47 * "defaults"; this second property list is searched if
48 * the property key is not found in the original property list.
49 * <p>
50 * Because {@code Properties} inherits from {@code Hashtable}, the
51 * {@code put} and {@code putAll} methods can be applied to a
52 * {@code Properties} object. Their use is strongly discouraged as they
53 * allow the caller to insert entries whose keys or values are not
54 * {@code Strings}. The {@code setProperty} method should be used
55 * instead. If the {@code store} or {@code save} method is called
56 * on a "compromised" {@code Properties} object that contains a
57 * non-{@code String} key or value, the call will fail. Similarly,
58 * the call to the {@code propertyNames} or {@code list} method
59 * will fail if it is called on a "compromised" {@code Properties}
60 * object that contains a non-{@code String} key.
61 *
62 * <p>
63 * The {@link #load(java.io.Reader) load(Reader)} {@code /}
64 * {@link #store(java.io.Writer, java.lang.String) store(Writer, String)}
65 * methods load and store properties from and to a character based stream
66 * in a simple line-oriented format specified below.
67 *
68 * The {@link #load(java.io.InputStream) load(InputStream)} {@code /}
69 * {@link #store(java.io.OutputStream, java.lang.String) store(OutputStream, String)}
70 * methods work the same way as the load(Reader)/store(Writer, String) pair, except
71 * the input/output stream is encoded in ISO 8859-1 character encoding.
72 * Characters that cannot be directly represented in this encoding can be written using
73 * Unicode escapes as defined in section 3.3 of
74 * <cite>The Java™ Language Specification</cite>;
75 * only a single 'u' character is allowed in an escape
76 * sequence.
77 *
78 * <p> The {@link #loadFromXML(InputStream)} and {@link
79 * #storeToXML(OutputStream, String, String)} methods load and store properties
80 * in a simple XML format. By default the UTF-8 character encoding is used,
81 * however a specific encoding may be specified if required. Implementations
82 * are required to support UTF-8 and UTF-16 and may support other encodings.
83 * An XML properties document has the following DOCTYPE declaration:
84 *
85 * <pre>
86 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
87 * </pre>
88 * Note that the system URI (http://java.sun.com/dtd/properties.dtd) is
89 * <i>not</i> accessed when exporting or importing properties; it merely
90 * serves as a string to uniquely identify the DTD, which is:
91 * <pre>
92 * <?xml version="1.0" encoding="UTF-8"?>
93 *
94 * <!-- DTD for properties -->
95 *
96 * <!ELEMENT properties ( comment?, entry* ) >
97 *
98 * <!ATTLIST properties version CDATA #FIXED "1.0">
99 *
100 * <!ELEMENT comment (#PCDATA) >
101 *
102 * <!ELEMENT entry (#PCDATA) >
103 *
104 * <!ATTLIST entry key CDATA #REQUIRED>
105 * </pre>
106 *
107 * <p>This class is thread-safe: multiple threads can share a single
108 * {@code Properties} object without the need for external synchronization.
109 *
110 * @author Arthur van Hoff
111 * @author Michael McCloskey
112 * @author Xueming Shen
113 * @since 1.0
114 */
115 public
116 class Properties extends Hashtable<Object,Object> {
117 /**
118 * use serialVersionUID from JDK 1.1.X for interoperability
119 */
120 private static final long serialVersionUID = 4112578634029874840L;
121
122 /**
123 * A property list that contains default values for any keys not
124 * found in this property list.
125 *
126 * @serial
127 */
128 protected Properties defaults;
129
130 /**
131 * Creates an empty property list with no default values.
132 */
133 public Properties() {
134 this(null);
135 }
136
137 /**
138 * Creates an empty property list with the specified defaults.
139 *
140 * @param defaults the defaults.
141 */
142 public Properties(Properties defaults) {
143 this.defaults = defaults;
144 }
145
146 /**
147 * Calls the {@code Hashtable} method {@code put}. Provided for
148 * parallelism with the {@code getProperty} method. Enforces use of
149 * strings for property keys and values. The value returned is the
150 * result of the {@code Hashtable} call to {@code put}.
151 *
152 * @param key the key to be placed into this property list.
153 * @param value the value corresponding to {@code key}.
154 * @return the previous value of the specified key in this property
155 * list, or {@code null} if it did not have one.
156 * @see #getProperty
157 * @since 1.2
158 */
159 public synchronized Object setProperty(String key, String value) {
160 return put(key, value);
161 }
162
163
164 /**
165 * Reads a property list (key and element pairs) from the input
166 * character stream in a simple line-oriented format.
167 * <p>
168 * Properties are processed in terms of lines. There are two
169 * kinds of line, <i>natural lines</i> and <i>logical lines</i>.
170 * A natural line is defined as a line of
171 * characters that is terminated either by a set of line terminator
172 * characters ({@code \n} or {@code \r} or {@code \r\n})
173 * or by the end of the stream. A natural line may be either a blank line,
739 * by the {@code toString} method of {@code Date} for the
740 * current time), and a line separator as generated by the {@code Writer}.
741 * <p>
742 * Then every entry in this {@code Properties} table is
743 * written out, one per line. For each entry the key string is
744 * written, then an ASCII {@code =}, then the associated
745 * element string. For the key, all space characters are
746 * written with a preceding {@code \} character. For the
747 * element, leading space characters, but not embedded or trailing
748 * space characters, are written with a preceding {@code \}
749 * character. The key and element characters {@code #},
750 * {@code !}, {@code =}, and {@code :} are written
751 * with a preceding backslash to ensure that they are properly loaded.
752 * <p>
753 * After the entries have been written, the output stream is flushed.
754 * The output stream remains open after this method returns.
755 *
756 * @param writer an output character stream writer.
757 * @param comments a description of the property list.
758 * @exception IOException if writing this property list to the specified
759 * output stream throws an {@code IOException}.
760 * @exception ClassCastException if this {@code Properties} object
761 * contains any keys or values that are not {@code Strings}.
762 * @exception NullPointerException if {@code writer} is null.
763 * @since 1.6
764 */
765 public void store(Writer writer, String comments)
766 throws IOException
767 {
768 store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
769 : new BufferedWriter(writer),
770 comments,
771 false);
772 }
773
774 /**
775 * Writes this property list (key and element pairs) in this
776 * {@code Properties} table to the output stream in a format suitable
777 * for loading into a {@code Properties} table using the
778 * {@link #load(InputStream) load(InputStream)} method.
779 * <p>
786 * with the following differences:
787 * <ul>
788 * <li>The stream is written using the ISO 8859-1 character encoding.
789 *
790 * <li>Characters not in Latin-1 in the comments are written as
791 * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
792 * hexadecimal value <i>xxxx</i>.
793 *
794 * <li>Characters less than {@code \u005Cu0020} and characters greater
795 * than {@code \u005Cu007E} in property keys or values are written
796 * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
797 * value <i>xxxx</i>.
798 * </ul>
799 * <p>
800 * After the entries have been written, the output stream is flushed.
801 * The output stream remains open after this method returns.
802 *
803 * @param out an output stream.
804 * @param comments a description of the property list.
805 * @exception IOException if writing this property list to the specified
806 * output stream throws an {@code IOException}.
807 * @exception ClassCastException if this {@code Properties} object
808 * contains any keys or values that are not {@code Strings}.
809 * @exception NullPointerException if {@code out} is null.
810 * @since 1.2
811 */
812 public void store(OutputStream out, String comments)
813 throws IOException
814 {
815 store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
816 comments,
817 true);
818 }
819
820 private void store0(BufferedWriter bw, String comments, boolean escUnicode)
821 throws IOException
822 {
823 if (comments != null) {
824 writeComments(bw, comments);
825 }
826 bw.write("#" + new Date().toString());
843
844 /**
845 * Loads all of the properties represented by the XML document on the
846 * specified input stream into this properties table.
847 *
848 * <p>The XML document must have the following DOCTYPE declaration:
849 * <pre>
850 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
851 * </pre>
852 * Furthermore, the document must satisfy the properties DTD described
853 * above.
854 *
855 * <p> An implementation is required to read XML documents that use the
856 * "{@code UTF-8}" or "{@code UTF-16}" encoding. An implementation may
857 * support additional encodings.
858 *
859 * <p>The specified stream is closed after this method returns.
860 *
861 * @param in the input stream from which to read the XML document.
862 * @throws IOException if reading from the specified input stream
863 * results in an {@code IOException}.
864 * @throws java.io.UnsupportedEncodingException if the document's encoding
865 * declaration can be read and it specifies an encoding that is not
866 * supported
867 * @throws InvalidPropertiesFormatException Data on input stream does not
868 * constitute a valid XML document with the mandated document type.
869 * @throws NullPointerException if {@code in} is null.
870 * @see #storeToXML(OutputStream, String, String)
871 * @see <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
872 * Encoding in Entities</a>
873 * @since 1.5
874 */
875 public synchronized void loadFromXML(InputStream in)
876 throws IOException, InvalidPropertiesFormatException
877 {
878 Objects.requireNonNull(in);
879 PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
880 handler.load(this, in);
881 in.close();
882 }
883
884 /**
885 * Emits an XML document representing all of the properties contained
886 * in this table.
887 *
888 * <p> An invocation of this method of the form {@code props.storeToXML(os,
889 * comment)} behaves in exactly the same way as the invocation
890 * {@code props.storeToXML(os, comment, "UTF-8");}.
891 *
892 * @param os the output stream on which to emit the XML document.
893 * @param comment a description of the property list, or {@code null}
894 * if no comment is desired.
895 * @throws IOException if writing to the specified output stream
896 * results in an {@code IOException}.
897 * @throws NullPointerException if {@code os} is null.
898 * @throws ClassCastException if this {@code Properties} object
899 * contains any keys or values that are not
900 * {@code Strings}.
901 * @see #loadFromXML(InputStream)
902 * @since 1.5
903 */
904 public void storeToXML(OutputStream os, String comment)
905 throws IOException
906 {
907 storeToXML(os, comment, "UTF-8");
908 }
909
910 /**
911 * Emits an XML document representing all of the properties contained
912 * in this table, using the specified encoding.
913 *
914 * <p>The XML document will have the following DOCTYPE declaration:
915 * <pre>
916 * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
917 * </pre>
918 *
919 * <p>If the specified comment is {@code null} then no comment
920 * will be stored in the document.
921 *
922 * <p> An implementation is required to support writing of XML documents
923 * that use the "{@code UTF-8}" or "{@code UTF-16}" encoding. An
924 * implementation may support additional encodings.
925 *
926 * <p>The specified stream remains open after this method returns.
927 *
928 * @param os the output stream on which to emit the XML document.
929 * @param comment a description of the property list, or {@code null}
930 * if no comment is desired.
931 * @param encoding the name of a supported
932 * <a href="../lang/package-summary.html#charenc">
933 * character encoding</a>
934 *
935 * @throws IOException if writing to the specified output stream
936 * results in an {@code IOException}.
937 * @throws java.io.UnsupportedEncodingException if the encoding is not
938 * supported by the implementation.
939 * @throws NullPointerException if {@code os} is {@code null},
940 * or if {@code encoding} is {@code null}.
941 * @throws ClassCastException if this {@code Properties} object
942 * contains any keys or values that are not
943 * {@code Strings}.
944 * @see #loadFromXML(InputStream)
945 * @see <a href="http://www.w3.org/TR/REC-xml/#charencoding">Character
946 * Encoding in Entities</a>
947 * @since 1.5
948 */
949 public void storeToXML(OutputStream os, String comment, String encoding)
950 throws IOException
951 {
952 Objects.requireNonNull(os);
953 Objects.requireNonNull(encoding);
954 PropertiesDefaultHandler handler = new PropertiesDefaultHandler();
955 handler.store(this, os, comment, encoding);
956 }
999 * @return an enumeration of all the keys in this property list, including
1000 * the keys in the default property list.
1001 * @throws ClassCastException if any key in this property list
1002 * is not a string.
1003 * @see java.util.Enumeration
1004 * @see java.util.Properties#defaults
1005 * @see #stringPropertyNames
1006 */
1007 public Enumeration<?> propertyNames() {
1008 Hashtable<String,Object> h = new Hashtable<>();
1009 enumerate(h);
1010 return h.keys();
1011 }
1012
1013 /**
1014 * Returns a set of keys in this property list where
1015 * the key and its corresponding value are strings,
1016 * including distinct keys in the default property list if a key
1017 * of the same name has not already been found from the main
1018 * properties list. Properties whose key or value is not
1019 * of type {@code String} are omitted.
1020 * <p>
1021 * The returned set is not backed by the {@code Properties} object.
1022 * Changes to this {@code Properties} are not reflected in the set,
1023 * or vice versa.
1024 *
1025 * @return a set of keys in this property list where
1026 * the key and its corresponding value are strings,
1027 * including the keys in the default property list.
1028 * @see java.util.Properties#defaults
1029 * @since 1.6
1030 */
1031 public Set<String> stringPropertyNames() {
1032 Hashtable<String, String> h = new Hashtable<>();
1033 enumerateStringProperties(h);
1034 return h.keySet();
1035 }
1036
1037 /**
1038 * Prints this property list out to the specified output stream.
1039 * This method is useful for debugging.
1040 *
1041 * @param out an output stream.
1042 * @throws ClassCastException if any key in this property list
|