Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Properties/SaveEncoding.java
41149 views
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 4026910 4011163 4077980 4096786 4213537
27
* @summary Test for saving and loading encoded keys and values
28
*/
29
30
import java.io.BufferedReader;
31
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.FileOutputStream;
34
import java.io.IOException;
35
import java.io.InputStreamReader;
36
import java.util.Properties;
37
38
/**
39
* This class tests to see if the properties object saves
40
* and loads keys and values properly
41
*/
42
public class SaveEncoding {
43
44
public static void main(String argv[]) {
45
int testSucceeded=0;
46
FileOutputStream myOutput;
47
48
// Create a properties object to save
49
Properties myProperties = new Properties();
50
myProperties.put("signal", "val\u0019");
51
myProperties.put("ABC 10", "value0");
52
myProperties.put("\uff10test", "value\u0020");
53
myProperties.put("key with spaces", "value with spaces");
54
myProperties.put(" special#=key ", "value3");
55
56
try {
57
// Destroy old test file if any
58
File myFile = new File("testout");
59
myFile.delete();
60
61
// Save the object and check output
62
myOutput = new FileOutputStream("testout");
63
myProperties.store(myOutput,"A test");
64
myOutput.close();
65
66
// Read properties file and verify \u0019
67
FileInputStream inFile = new FileInputStream("testout");
68
BufferedReader in = new BufferedReader(
69
new InputStreamReader(inFile));
70
String firstLine = "foo";
71
while (!firstLine.startsWith("signal"))
72
firstLine = in.readLine();
73
inFile.close();
74
if (firstLine.length() != 16)
75
throw new RuntimeException(
76
"Incorrect storage of values < 32.");
77
78
// Load the properties set
79
FileInputStream myIn = new FileInputStream("testout");
80
Properties myNewProps = new Properties();
81
try {
82
myNewProps.load(myIn);
83
} finally {
84
myIn.close();
85
}
86
87
// Check the results
88
if (!myNewProps.equals(myProperties))
89
throw new RuntimeException(
90
"Properties is not character encoding safe.");
91
} catch (IOException e) { // Do nothing
92
}
93
}
94
}
95
96