Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/FontClass/CreateFont/DeleteFont.java
38828 views
1
/*
2
* Copyright (c) 2004, 2008, 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.io.*;
25
import java.awt.*;
26
27
public class DeleteFont {
28
29
public static void main(String args[]) throws Exception {
30
31
String font = "A.ttf";
32
String sep = System.getProperty("file.separator");
33
String testSrc = System.getenv("TESTSRC");
34
if (testSrc != null) {
35
font = testSrc + sep + font;
36
}
37
System.out.println("Using font file: " + font);
38
FileInputStream fis = new FileInputStream(font);
39
Font f = Font.createFont(Font.TRUETYPE_FONT, fis);
40
f.toString();
41
f.deriveFont(Font.BOLD);
42
f.canDisplay('X');
43
44
InputStream in = new InputStream() {
45
public int read() {
46
throw new RuntimeException();
47
}
48
};
49
boolean gotException = false;
50
try {
51
Font.createFont(java.awt.Font.TRUETYPE_FONT, in);
52
} catch (IOException e) {
53
gotException = true;
54
}
55
if (!gotException) {
56
throw new RuntimeException("No expected IOException");
57
}
58
badRead(-2, Font.TRUETYPE_FONT);
59
badRead(8193, Font.TRUETYPE_FONT);
60
61
badRead(-2, Font.TYPE1_FONT);
62
badRead(8193, Font.TYPE1_FONT);
63
64
// Make sure GC has a chance to clean up before we exit.
65
System.gc(); System.gc();
66
}
67
68
static void badRead(final int retval, int fontType) {
69
int num = 2;
70
byte[] buff = new byte[16*8192]; // Multiple of 8192 is important.
71
for (int ct=0; ct<num; ++ct) {
72
try {
73
Font.createFont(
74
fontType,
75
new ByteArrayInputStream(buff) {
76
@Override
77
public int read(byte[] buff, int off, int len) {
78
int read = super.read(buff, off, len);
79
return read<0 ? retval : read;
80
}
81
}
82
);
83
} catch (Throwable exc) {
84
//exc.printStackTrace();
85
}
86
}
87
}
88
}
89
90
91