Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/io/Serializable/defaulted/GetFieldWrite.java
41154 views
1
/*
2
* Copyright (c) 1999, 2019, 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
/* @test
25
* @bug 4180735
26
*
27
* @clean GetFieldWrite Foo TestClass
28
* @build GetFieldWrite
29
* @run main GetFieldWrite
30
* @clean GetFieldRead TestClass
31
* @build GetFieldRead
32
* @run main GetFieldRead
33
*
34
* @summary Make sure that fields that are defaulted can be of primitive and
35
* object type.
36
*
37
*/
38
39
import java.io.*;
40
class TestClass implements Serializable {
41
42
private static final long serialVersionUID = 5748652654655279289L;
43
44
// Fields to be serialized.
45
private static final ObjectStreamField[] serialPersistentFields = {
46
new ObjectStreamField("objectI", Integer.class)};
47
48
Integer objectI;
49
int primitiveI;
50
Foo foo;
51
52
public TestClass(Foo f, Integer I, int i) {
53
foo = f;
54
objectI = I;
55
primitiveI = i;
56
}
57
};
58
59
public class GetFieldWrite {
60
public static void main(String[] args)
61
throws ClassNotFoundException, IOException
62
{
63
FileOutputStream fos = new FileOutputStream("data.ser");
64
ObjectOutput out = new ObjectOutputStream(fos);
65
out.writeObject(new TestClass(new Foo(100, 200), 100, 200));
66
out.close();
67
}
68
};
69
70
/*
71
* Test class to be used as data field
72
*/
73
class Foo implements Serializable{
74
private static final long serialVersionUID = 1L;
75
76
int a;
77
int b;
78
public Foo() {
79
a = 10; b= 20;
80
}
81
82
public Foo(int a1, int b1)
83
{
84
a = a1; b = b1;
85
}
86
87
public String toString() {
88
return new String("a = " + a + " b = " + b);
89
}
90
}
91
92