Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/stream/StreamCloserLeak/testapp/Main.java
41155 views
1
/*
2
* Copyright (c) 2009, 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
package testapp;
25
26
import java.io.ByteArrayInputStream;
27
import java.io.File;
28
import java.io.IOException;
29
import java.io.InputStream;
30
import java.util.HashMap;
31
import java.util.concurrent.ConcurrentLinkedQueue;
32
import javax.imageio.stream.FileCacheImageInputStream;
33
import javax.imageio.stream.ImageInputStream;
34
35
public class Main {
36
37
public static void main(String[] args) {
38
Main o = new Main("testapp.some.class", null);
39
o.launch(null);
40
}
41
42
private final String uniqClassName;
43
private final ConcurrentLinkedQueue<Throwable> problems;
44
45
public Main(String uniq, ConcurrentLinkedQueue<Throwable> p) {
46
uniqClassName = uniq;
47
problems = p;
48
}
49
50
public void launch(HashMap<String, ImageInputStream> refs) {
51
System.out.printf("%s: current context class loader: %s\n",
52
uniqClassName,
53
Thread.currentThread().getContextClassLoader());
54
try {
55
byte[] data = new byte[1024];
56
ByteArrayInputStream bais = new ByteArrayInputStream(data);
57
MyImageInputStream iis = new MyImageInputStream(bais,
58
uniqClassName,
59
problems);
60
if (refs != null) {
61
System.out.printf("%s: added to strong store\n",
62
uniqClassName);
63
refs.put(uniqClassName, iis);
64
}
65
iis.read();
66
//leave stream open : let's shutdown hook work!
67
} catch (IOException e) {
68
problems.add(e);
69
}
70
}
71
72
private static class MyImageInputStream extends FileCacheImageInputStream {
73
private final String uniqClassName;
74
private ConcurrentLinkedQueue<Throwable> problems;
75
public MyImageInputStream(InputStream is, String uniq,
76
ConcurrentLinkedQueue<Throwable> p) throws IOException
77
{
78
super(is, new File("tmp"));
79
uniqClassName = uniq;
80
problems = p;
81
}
82
83
@Override
84
public void close() throws IOException {
85
Test t = new Test();
86
try {
87
t.doTest(uniqClassName);
88
} catch (Throwable e) {
89
problems.add(e);
90
}
91
92
super.close();
93
94
problems = null;
95
}
96
}
97
}
98
99
class Test {
100
public void doTest(String uniqClassName) throws ClassNotFoundException {
101
System.out.printf("%s: Current thread: %s\n", uniqClassName,
102
Thread.currentThread());
103
104
ClassLoader thisCL = this.getClass().getClassLoader();
105
Class uniq = thisCL.loadClass(uniqClassName);
106
107
System.out.printf("%s: test is done!\n",uniqClassName);
108
}
109
}
110
111