Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/awt/datatransfer/SuplementaryCharactersTransferTest.java
38839 views
1
/*
2
* Copyright (c) 2013, 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 6877495
26
@summary JTextField and JTextArea does not support supplementary characters
27
@author Alexander Scherbatiy
28
@run main SuplementaryCharactersTransferTest
29
*/
30
31
32
import java.io.*;
33
import java.util.*;
34
import java.awt.*;
35
import java.awt.datatransfer.*;
36
import sun.awt.datatransfer.*;
37
import sun.awt.datatransfer.DataTransferer.ReencodingInputStream;
38
39
public class SuplementaryCharactersTransferTest {
40
41
public static final long TEXT_FORMAT = 13;
42
43
public static void main(String[] args) throws Exception {
44
45
DataTransferer dataTransferer = new TestDataTransferer();
46
dataTransferer.registerTextFlavorProperties("UNICODE TEXT", "utf-16le", "\r\n", "2");
47
ByteTransferable transferable = new ByteTransferable();
48
ReencodingInputStream is = dataTransferer.new ReencodingInputStream(transferable.getByteInputStream(), TEXT_FORMAT,
49
DataTransferer.getTextCharset(transferable.getDataFlavor()), transferable);
50
51
byte[] bytes = transferable.getBytes();
52
byte[] result = new byte[bytes.length];
53
54
is.read(result);
55
56
for (int i = 0; i < bytes.length; i++) {
57
if (bytes[i] != result[i]) {
58
throw new RuntimeException("Characters are not equal!");
59
}
60
}
61
62
}
63
64
static class ByteTransferable implements Transferable, ClipboardOwner {
65
66
private final DataFlavor dataFlavor;
67
68
public ByteTransferable() throws Exception {
69
dataFlavor = DataFlavor.getTextPlainUnicodeFlavor();
70
}
71
72
public DataFlavor getDataFlavor() {
73
return dataFlavor;
74
}
75
76
public DataFlavor[] getTransferDataFlavors() {
77
return new DataFlavor[]{dataFlavor};
78
}
79
80
public boolean isDataFlavorSupported(DataFlavor flavor) {
81
return flavor.equals(dataFlavor);
82
}
83
84
public byte[] getBytes() {
85
return new byte[]{97, 0, 64, -40, 32, -36, 98, 0};
86
}
87
88
public InputStream getByteInputStream() {
89
return new ByteArrayInputStream(getBytes());
90
}
91
92
public Object getTransferData(DataFlavor flavor)
93
throws UnsupportedFlavorException, IOException {
94
if (flavor.equals(dataFlavor)) {
95
return getByteInputStream();
96
} else {
97
throw new UnsupportedFlavorException(flavor);
98
}
99
}
100
101
public void lostOwnership(Clipboard clipboard, Transferable contents) {
102
}
103
}
104
105
static class TestDataTransferer extends DataTransferer {
106
107
@Override
108
public String getDefaultUnicodeEncoding() {
109
throw new UnsupportedOperationException("Not supported yet.");
110
}
111
112
@Override
113
public boolean isLocaleDependentTextFormat(long format) {
114
return false;
115
}
116
117
@Override
118
public boolean isFileFormat(long format) {
119
throw new UnsupportedOperationException("Not supported yet.");
120
}
121
122
@Override
123
public boolean isImageFormat(long format) {
124
throw new UnsupportedOperationException("Not supported yet.");
125
}
126
127
@Override
128
protected Long getFormatForNativeAsLong(String str) {
129
return TEXT_FORMAT;
130
}
131
132
@Override
133
protected String getNativeForFormat(long format) {
134
throw new UnsupportedOperationException("Not supported yet.");
135
}
136
137
@Override
138
protected ByteArrayOutputStream convertFileListToBytes(
139
ArrayList<String> fileList) throws IOException {
140
throw new UnsupportedOperationException("Not supported yet.");
141
}
142
143
@Override
144
protected String[] dragQueryFile(byte[] bytes) {
145
throw new UnsupportedOperationException("Not supported yet.");
146
}
147
148
@Override
149
protected byte[] imageToPlatformBytes(Image image, long format)
150
throws IOException {
151
throw new UnsupportedOperationException("Not supported yet.");
152
}
153
154
@Override
155
public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
156
throw new UnsupportedOperationException("Not supported yet.");
157
}
158
159
@Override
160
protected Image platformImageBytesToImage(byte[] bytes, long format) throws IOException {
161
throw new UnsupportedOperationException("Not supported yet.");
162
}
163
}
164
}
165