src/share/classes/java/util/Properties.java

Print this page




 737      * after that line separator.
 738      * <p>
 739      * Next, a comment line is always written, consisting of an ASCII
 740      * {@code #} character, the current date and time (as if produced
 741      * by the {@code toString} method of {@code Date} for the
 742      * current time), and a line separator as generated by the {@code Writer}.
 743      * <p>
 744      * Then every entry in this {@code Properties} table is
 745      * written out, one per line. For each entry the key string is
 746      * written, then an ASCII {@code =}, then the associated
 747      * element string. For the key, all space characters are
 748      * written with a preceding {@code \} character.  For the
 749      * element, leading space characters, but not embedded or trailing
 750      * space characters, are written with a preceding {@code \}
 751      * character. The key and element characters {@code #},
 752      * {@code !}, {@code =}, and {@code :} are written
 753      * with a preceding backslash to ensure that they are properly loaded.
 754      * <p>
 755      * After the entries have been written, the output stream is flushed.
 756      * The output stream remains open after this method returns.
 757      * <p>
 758      *
 759      * @param   writer      an output character stream writer.
 760      * @param   comments   a description of the property list.
 761      * @exception  IOException if writing this property list to the specified
 762      *             output stream throws an <tt>IOException</tt>.
 763      * @exception  ClassCastException  if this {@code Properties} object
 764      *             contains any keys or values that are not {@code Strings}.
 765      * @exception  NullPointerException  if {@code writer} is null.
 766      * @since 1.6
 767      */
 768     public void store(Writer writer, String comments)
 769         throws IOException
 770     {
 771         store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
 772                                                  : new BufferedWriter(writer),
 773                comments,
 774                false);
 775     }
 776 
 777     /**


 785      * <p>
 786      * This method outputs the comments, properties keys and values in
 787      * the same format as specified in
 788      * {@link #store(java.io.Writer, java.lang.String) store(Writer)},
 789      * with the following differences:
 790      * <ul>
 791      * <li>The stream is written using the ISO 8859-1 character encoding.
 792      *
 793      * <li>Characters not in Latin-1 in the comments are written as
 794      * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
 795      * hexadecimal value <i>xxxx</i>.
 796      *
 797      * <li>Characters less than {@code \u005Cu0020} and characters greater
 798      * than {@code \u005Cu007E} in property keys or values are written
 799      * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
 800      * value <i>xxxx</i>.
 801      * </ul>
 802      * <p>
 803      * After the entries have been written, the output stream is flushed.
 804      * The output stream remains open after this method returns.
 805      * <p>
 806      * @param   out      an output stream.
 807      * @param   comments   a description of the property list.
 808      * @exception  IOException if writing this property list to the specified
 809      *             output stream throws an <tt>IOException</tt>.
 810      * @exception  ClassCastException  if this {@code Properties} object
 811      *             contains any keys or values that are not {@code Strings}.
 812      * @exception  NullPointerException  if {@code out} is null.
 813      * @since 1.2
 814      */
 815     public void store(OutputStream out, String comments)
 816         throws IOException
 817     {
 818         store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
 819                comments,
 820                true);
 821     }
 822 
 823     private void store0(BufferedWriter bw, String comments, boolean escUnicode)
 824         throws IOException
 825     {




 737      * after that line separator.
 738      * <p>
 739      * Next, a comment line is always written, consisting of an ASCII
 740      * {@code #} character, the current date and time (as if produced
 741      * by the {@code toString} method of {@code Date} for the
 742      * current time), and a line separator as generated by the {@code Writer}.
 743      * <p>
 744      * Then every entry in this {@code Properties} table is
 745      * written out, one per line. For each entry the key string is
 746      * written, then an ASCII {@code =}, then the associated
 747      * element string. For the key, all space characters are
 748      * written with a preceding {@code \} character.  For the
 749      * element, leading space characters, but not embedded or trailing
 750      * space characters, are written with a preceding {@code \}
 751      * character. The key and element characters {@code #},
 752      * {@code !}, {@code =}, and {@code :} are written
 753      * with a preceding backslash to ensure that they are properly loaded.
 754      * <p>
 755      * After the entries have been written, the output stream is flushed.
 756      * The output stream remains open after this method returns.

 757      *
 758      * @param   writer      an output character stream writer.
 759      * @param   comments   a description of the property list.
 760      * @exception  IOException if writing this property list to the specified
 761      *             output stream throws an <tt>IOException</tt>.
 762      * @exception  ClassCastException  if this {@code Properties} object
 763      *             contains any keys or values that are not {@code Strings}.
 764      * @exception  NullPointerException  if {@code writer} is null.
 765      * @since 1.6
 766      */
 767     public void store(Writer writer, String comments)
 768         throws IOException
 769     {
 770         store0((writer instanceof BufferedWriter)?(BufferedWriter)writer
 771                                                  : new BufferedWriter(writer),
 772                comments,
 773                false);
 774     }
 775 
 776     /**


 784      * <p>
 785      * This method outputs the comments, properties keys and values in
 786      * the same format as specified in
 787      * {@link #store(java.io.Writer, java.lang.String) store(Writer)},
 788      * with the following differences:
 789      * <ul>
 790      * <li>The stream is written using the ISO 8859-1 character encoding.
 791      *
 792      * <li>Characters not in Latin-1 in the comments are written as
 793      * {@code \u005Cu}<i>xxxx</i> for their appropriate unicode
 794      * hexadecimal value <i>xxxx</i>.
 795      *
 796      * <li>Characters less than {@code \u005Cu0020} and characters greater
 797      * than {@code \u005Cu007E} in property keys or values are written
 798      * as {@code \u005Cu}<i>xxxx</i> for the appropriate hexadecimal
 799      * value <i>xxxx</i>.
 800      * </ul>
 801      * <p>
 802      * After the entries have been written, the output stream is flushed.
 803      * The output stream remains open after this method returns.
 804      *
 805      * @param   out      an output stream.
 806      * @param   comments   a description of the property list.
 807      * @exception  IOException if writing this property list to the specified
 808      *             output stream throws an <tt>IOException</tt>.
 809      * @exception  ClassCastException  if this {@code Properties} object
 810      *             contains any keys or values that are not {@code Strings}.
 811      * @exception  NullPointerException  if {@code out} is null.
 812      * @since 1.2
 813      */
 814     public void store(OutputStream out, String comments)
 815         throws IOException
 816     {
 817         store0(new BufferedWriter(new OutputStreamWriter(out, "8859_1")),
 818                comments,
 819                true);
 820     }
 821 
 822     private void store0(BufferedWriter bw, String comments, boolean escUnicode)
 823         throws IOException
 824     {