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