src/java.base/share/classes/java/util/Properties.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 55009 cdb107ca16e6
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
     1 /*
     1 /*
     2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1995, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   140 public
   140 public
   141 class Properties extends Hashtable<Object,Object> {
   141 class Properties extends Hashtable<Object,Object> {
   142     /**
   142     /**
   143      * use serialVersionUID from JDK 1.1.X for interoperability
   143      * use serialVersionUID from JDK 1.1.X for interoperability
   144      */
   144      */
       
   145     @java.io.Serial
   145     private static final long serialVersionUID = 4112578634029874840L;
   146     private static final long serialVersionUID = 4112578634029874840L;
   146 
   147 
   147     private static final Unsafe UNSAFE = Unsafe.getUnsafe();
   148     private static final Unsafe UNSAFE = Unsafe.getUnsafe();
   148 
   149 
   149     /**
   150     /**
   391      * <cite>The Java&trade; Language Specification</cite>.
   392      * <cite>The Java&trade; Language Specification</cite>.
   392      * <p>
   393      * <p>
   393      * The specified stream remains open after this method returns.
   394      * The specified stream remains open after this method returns.
   394      *
   395      *
   395      * @param      inStream   the input stream.
   396      * @param      inStream   the input stream.
   396      * @exception  IOException  if an error occurred when reading from the
   397      * @throws     IOException  if an error occurred when reading from the
   397      *             input stream.
   398      *             input stream.
   398      * @throws     IllegalArgumentException if the input stream contains a
   399      * @throws     IllegalArgumentException if the input stream contains a
   399      *             malformed Unicode escape sequence.
   400      *             malformed Unicode escape sequence.
   400      * @throws     NullPointerException if {@code inStream} is null.
   401      * @throws     NullPointerException if {@code inStream} is null.
   401      * @since 1.2
   402      * @since 1.2
   639         out.append(in, start, off - start);
   640         out.append(in, start, off - start);
   640 
   641 
   641         while (off < end) {
   642         while (off < end) {
   642             aChar = in[off++];
   643             aChar = in[off++];
   643             if (aChar == '\\') {
   644             if (aChar == '\\') {
       
   645                 // No need to bounds check since LineReader::readLine excludes
       
   646                 // unescaped \s at the end of the line
   644                 aChar = in[off++];
   647                 aChar = in[off++];
   645                 if(aChar == 'u') {
   648                 if(aChar == 'u') {
   646                     // Read the xxxx
   649                     // Read the xxxx
   647                     int value=0;
   650                     if (off > end - 4)
   648                     for (int i=0; i<4; i++) {
   651                         throw new IllegalArgumentException(
       
   652                                      "Malformed \\uxxxx encoding.");
       
   653                     int value = 0;
       
   654                     for (int i = 0; i < 4; i++) {
   649                         aChar = in[off++];
   655                         aChar = in[off++];
   650                         switch (aChar) {
   656                         switch (aChar) {
   651                           case '0': case '1': case '2': case '3': case '4':
   657                           case '0': case '1': case '2': case '3': case '4':
   652                           case '5': case '6': case '7': case '8': case '9':
   658                           case '5': case '6': case '7': case '8': case '9':
   653                              value = (value << 4) + aChar - '0';
   659                              value = (value << 4) + aChar - '0';
   793      * String comments)} method or the
   799      * String comments)} method or the
   794      * {@code storeToXML(OutputStream os, String comment)} method.
   800      * {@code storeToXML(OutputStream os, String comment)} method.
   795      *
   801      *
   796      * @param   out      an output stream.
   802      * @param   out      an output stream.
   797      * @param   comments   a description of the property list.
   803      * @param   comments   a description of the property list.
   798      * @exception  ClassCastException  if this {@code Properties} object
   804      * @throws     ClassCastException  if this {@code Properties} object
   799      *             contains any keys or values that are not
   805      *             contains any keys or values that are not
   800      *             {@code Strings}.
   806      *             {@code Strings}.
   801      */
   807      */
   802     @Deprecated
   808     @Deprecated
   803     public void save(OutputStream out, String comments)  {
   809     public void save(OutputStream out, String comments)  {
   845      * After the entries have been written, the output stream is flushed.
   851      * After the entries have been written, the output stream is flushed.
   846      * The output stream remains open after this method returns.
   852      * The output stream remains open after this method returns.
   847      *
   853      *
   848      * @param   writer      an output character stream writer.
   854      * @param   writer      an output character stream writer.
   849      * @param   comments   a description of the property list.
   855      * @param   comments   a description of the property list.
   850      * @exception  IOException if writing this property list to the specified
   856      * @throws     IOException if writing this property list to the specified
   851      *             output stream throws an {@code IOException}.
   857      *             output stream throws an {@code IOException}.
   852      * @exception  ClassCastException  if this {@code Properties} object
   858      * @throws     ClassCastException  if this {@code Properties} object
   853      *             contains any keys or values that are not {@code Strings}.
   859      *             contains any keys or values that are not {@code Strings}.
   854      * @exception  NullPointerException  if {@code writer} is null.
   860      * @throws     NullPointerException  if {@code writer} is null.
   855      * @since 1.6
   861      * @since 1.6
   856      */
   862      */
   857     public void store(Writer writer, String comments)
   863     public void store(Writer writer, String comments)
   858         throws IOException
   864         throws IOException
   859     {
   865     {
   892      * After the entries have been written, the output stream is flushed.
   898      * After the entries have been written, the output stream is flushed.
   893      * The output stream remains open after this method returns.
   899      * The output stream remains open after this method returns.
   894      *
   900      *
   895      * @param   out      an output stream.
   901      * @param   out      an output stream.
   896      * @param   comments   a description of the property list.
   902      * @param   comments   a description of the property list.
   897      * @exception  IOException if writing this property list to the specified
   903      * @throws     IOException if writing this property list to the specified
   898      *             output stream throws an {@code IOException}.
   904      *             output stream throws an {@code IOException}.
   899      * @exception  ClassCastException  if this {@code Properties} object
   905      * @throws     ClassCastException  if this {@code Properties} object
   900      *             contains any keys or values that are not {@code Strings}.
   906      *             contains any keys or values that are not {@code Strings}.
   901      * @exception  NullPointerException  if {@code out} is null.
   907      * @throws     NullPointerException  if {@code out} is null.
   902      * @since 1.2
   908      * @since 1.2
   903      */
   909      */
   904     public void store(OutputStream out, String comments)
   910     public void store(OutputStream out, String comments)
   905         throws IOException
   911         throws IOException
   906     {
   912     {