Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSpinner/SerializationTest.java
41152 views
1
/*
2
* Copyright (c) 2020, 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
import java.awt.EventQueue;
25
import java.io.ByteArrayInputStream;
26
import java.io.ByteArrayOutputStream;
27
import java.io.InputStream;
28
import java.io.ObjectInputStream;
29
import java.io.ObjectOutputStream;
30
import java.io.Serializable;
31
32
import javax.swing.JSpinner;
33
import javax.swing.UIManager;
34
import javax.swing.UnsupportedLookAndFeelException;
35
36
import static javax.swing.UIManager.getInstalledLookAndFeels;
37
38
/**
39
* @test
40
* @bug 7124397 8256376
41
* @key headful
42
* @summary Verifies that JSpinner can be serialized/deserialized correctly.
43
* @run main/othervm SerializationTest
44
* @run main/othervm -Djava.awt.headless=true SerializationTest
45
*/
46
public final class SerializationTest {
47
48
public static void main(String[] argv) throws Exception {
49
for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
50
EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
51
EventQueue.invokeAndWait(() -> {
52
JSpinner spinner = new JSpinner();
53
JSpinner firstCopy = (JSpinner) createCopy(spinner);
54
JSpinner secondCopy = (JSpinner) createCopy(firstCopy);
55
});
56
}
57
}
58
59
private static Object createCopy(Serializable objectToCopy) {
60
try {
61
ByteArrayOutputStream baos = new ByteArrayOutputStream();
62
ObjectOutputStream oos = new ObjectOutputStream(baos);
63
oos.writeObject(objectToCopy);
64
InputStream bais = new ByteArrayInputStream(baos.toByteArray());
65
ObjectInputStream ois = new ObjectInputStream(bais);
66
return ois.readObject();
67
} catch (Exception e) {
68
throw new RuntimeException(e);
69
}
70
}
71
72
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
73
try {
74
UIManager.setLookAndFeel(laf.getClassName());
75
} catch (UnsupportedLookAndFeelException ignored) {
76
System.out.println("Unsupported LookAndFeel: " + laf.getClassName());
77
} catch (Exception e) {
78
throw new RuntimeException(e);
79
}
80
}
81
}
82
83