--- old/src/java.base/share/classes/java/util/Properties.java 2017-12-11 11:59:46.642147984 -0800 +++ new/src/java.base/share/classes/java/util/Properties.java 2017-12-11 11:59:46.370134363 -0800 @@ -37,6 +37,10 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.StreamCorruptedException; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.nio.charset.IllegalCharsetNameException; +import java.nio.charset.UnsupportedCharsetException; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; @@ -997,6 +1001,11 @@ * *

The specified stream remains open after this method returns. * + *

This method behaves the same as + * {@linkplain #storeToXML(OutputStream os, String comment, Charset charset)} + * except that it will {@linkplain java.nio.charset.Charset#forName look up the charset} + * using the given encoding name. + * * @param os the output stream on which to emit the XML document. * @param comment a description of the property list, or {@code null} * if no comment is desired. @@ -1011,20 +1020,67 @@ * @throws NullPointerException if {@code os} is {@code null}, * or if {@code encoding} is {@code null}. * @throws ClassCastException if this {@code Properties} object - * contains any keys or values that are not - * {@code Strings}. + * contains any keys or values that are not {@code Strings}. * @see #loadFromXML(InputStream) * @see Character * Encoding in Entities * @since 1.5 */ public void storeToXML(OutputStream os, String comment, String encoding) - throws IOException - { + throws IOException { Objects.requireNonNull(os); Objects.requireNonNull(encoding); + + try { + Charset charset = Charset.forName(encoding); + storeToXML(os, comment, charset); + } catch (IllegalCharsetNameException | UnsupportedCharsetException e) { + throw new UnsupportedEncodingException(encoding); + } + } + + /** + * Emits an XML document representing all of the properties contained + * in this table, using the specified encoding. + * + *

The XML document will have the following DOCTYPE declaration: + *

+     * <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+     * 
+ * + *

If the specified comment is {@code null} then no comment + * will be stored in the document. + * + *

An implementation is required to support writing of XML documents + * that use the "{@code UTF-8}" or "{@code UTF-16}" encoding. An + * implementation may support additional encodings. + * + *

Unmappable characters for the specified charset will be encoded as + * numeric character references. + * + *

The specified stream remains open after this method returns. + * + * @param os the output stream on which to emit the XML document. + * @param comment a description of the property list, or {@code null} + * if no comment is desired. + * @param charset the charset + * + * @throws IOException if writing to the specified output stream + * results in an {@code IOException}. + * @throws NullPointerException if {@code os} or {@code charset} is {@code null}. + * @throws ClassCastException if this {@code Properties} object + * contains any keys or values that are not {@code Strings}. + * @see #loadFromXML(InputStream) + * @see Character + * Encoding in Entities + * @since 10 + */ + public void storeToXML(OutputStream os, String comment, Charset charset) + throws IOException { + Objects.requireNonNull(os, "OutputStream"); + Objects.requireNonNull(charset, "Charset"); PropertiesDefaultHandler handler = new PropertiesDefaultHandler(); - handler.store(this, os, comment, encoding); + handler.store(this, os, comment, charset); } /**