• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
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
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /*
25  * @test
26  * @bug 4192678
27  * @summary Test loading of values that are key value separators
28  */
29 
30 package test.java.util.Properties;
31 
32 import java.io.File;
33 import java.io.FileInputStream;
34 import java.io.FileOutputStream;
35 import java.io.IOException;
36 import java.util.Properties;
37 
38 /**
39  * This class tests to see if a properties object can successfully save and
40  * load properties with a non-escaped value that is also a key value separator
41  *
42  */
43 public class LoadSeparators {
main(String[] argv)44     public static void main(String[] argv) throws Exception {
45         try {
46             // Destroy old test file if any
47             // Create a properties file
48             // Android-changed: create temp file.
49             // File propFile = new File("testout");
50             // propFile.delete();
51             File propFile = File.createTempFile("testout", "properties");
52 
53             // Create a properties file
54             FileOutputStream myOut = new FileOutputStream(propFile);
55             String testProperty = "Test3==";
56             myOut.write(testProperty.getBytes());
57             myOut.close();
58 
59             // Load the properties set
60             // Android-changed: read from temp file.
61             // FileInputStream myIn = new FileInputStream("testout");
62             FileInputStream myIn = new FileInputStream(propFile);
63             Properties myNewProps = new Properties();
64             try {
65                 myNewProps.load(myIn);
66             } finally {
67                 myIn.close();
68             }
69 
70             // Read in the test property
71             String equalSign = myNewProps.getProperty("Test3");
72 
73             // Clean up
74             propFile.delete();
75 
76             if (!equalSign.equals("="))
77                 throw new Exception("Cannot read key-value separators.");
78         } catch (IOException e) {
79             System.err.println(e);
80         }
81     }
82 }
83