Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/common/Bug4769840.java
41152 views
1
/*
2
* Copyright (c) 2003, 2016, 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 1.1 03/10/27
26
* @bug 4769840
27
* @library /java/text/testlib
28
* @build Bug4769840 HexDumpReader
29
* @run main Bug4769840
30
* @summary Confirm serialization compatibility
31
*/
32
33
import java.io.*;
34
import java.text.*;
35
36
public class Bug4769840 {
37
38
public static void main(String[] args) throws Exception {
39
if (args.length == 1 && args[0].equals("-ser")) {
40
serialize();
41
} else {
42
deserialize();
43
}
44
}
45
46
/* Serialization */
47
private static void serialize() throws Exception {
48
/* Serialize with JDK 1.1 */
49
serialize("ChoiceFormat.ser", new ChoiceFormat("0# foo|1# bar"));
50
51
/*
52
* Serialize with JDK1.4.0 because the Field class was added in the
53
* version.
54
*/
55
serialize("DateFormat.Field.ser", DateFormat.Field.TIME_ZONE);
56
serialize("MessageFormat.Field.ser", MessageFormat.Field.ARGUMENT);
57
serialize("NumberFormat.Field.ser", NumberFormat.Field.INTEGER);
58
}
59
60
private static void serialize(String filename, Object o) throws Exception {
61
FileOutputStream fos = new FileOutputStream(filename);
62
ObjectOutputStream out = new ObjectOutputStream(fos);
63
out.writeObject(o);
64
out.close();
65
}
66
67
/* Deserialization */
68
private static void deserialize() throws Exception {
69
deserialize("ChoiceFormat.ser");
70
deserialize("DateFormat.Field.ser");
71
deserialize("MessageFormat.Field.ser");
72
deserialize("NumberFormat.Field.ser");
73
}
74
75
private static void deserialize(String filename) throws Exception {
76
InputStream is = HexDumpReader.getStreamFromHexDump(filename + ".txt");
77
ObjectInputStream in = new ObjectInputStream(is);
78
Object obj = in.readObject();
79
in.close();
80
System.out.println("Deserialization of <" + filename + "> succeeded.");
81
}
82
}
83
84