Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Properties/BlankLines.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 4218776
27
* @summary Test loading of properties files with blank lines
28
*/
29
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.io.FileOutputStream;
33
import java.io.IOException;
34
import java.io.InputStream;
35
import java.util.Properties;
36
37
/**
38
* This class tests to see if a properties object correctly handles blank
39
* lines in a properties file
40
*/
41
public class BlankLines {
42
public static void main(String []args)
43
{
44
try {
45
// create test file
46
File file = new File("test.properties");
47
48
// write a single space to the test file
49
FileOutputStream fos = new FileOutputStream(file);
50
fos.write(' ');
51
fos.close();
52
53
// test empty properties
54
Properties prop1 = new Properties();
55
56
// now load the file we just created, into a
57
// properties object.
58
// the properties object should have no elements,
59
// but due to a bug, it has an empty key/value.
60
// key = "", value = ""
61
Properties prop2 = new Properties();
62
InputStream is = new FileInputStream(file);
63
try {
64
prop2.load(is);
65
} finally {
66
is.close();
67
}
68
if (!prop1.equals(prop2))
69
throw new RuntimeException("Incorrect properties loading.");
70
71
// cleanup
72
file.delete();
73
}
74
catch(IOException e) {}
75
}
76
}
77
78