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/net/www/protocol/http/Finalizer.java
38867 views
1
/*
2
* Copyright (c) 2000, 2001, 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 4372248
26
@summary Java2D demo throws exceptions on MerlinB32
27
*/
28
import java.io.*;
29
import java.net.*;
30
class XServer extends Thread {
31
ServerSocket srv;
32
Socket s;
33
InputStream is;
34
OutputStream os;
35
36
XServer (ServerSocket s) {
37
srv = s;
38
}
39
40
Socket getSocket () {
41
return (s);
42
}
43
44
public void run() {
45
try {
46
String x;
47
String msg = "Message from the server\r\n";
48
s = srv.accept ();
49
is = s.getInputStream ();
50
BufferedReader r = new BufferedReader(new InputStreamReader(is));
51
os = s.getOutputStream ();
52
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os));
53
while ((x=r.readLine()) != null) {
54
if (x.length() == 0)
55
break;
56
}
57
w.write("HTTP/1.1 200\r\n");
58
w.write("Content-Type: text/html\r\n");
59
w.write("Content-Length: "+msg.length()+"\r\n");
60
w.write("\r\n");
61
w.write(msg);
62
w.flush();
63
64
// second round
65
while ((x=r.readLine()) != null) {
66
if (x.length() == 0)
67
break;
68
}
69
w.write("HTTP/1.1 200\r\n");
70
w.write("Content-Type: text/html\r\n");
71
w.write("Content-Length: "+msg.length()+"\r\n");
72
w.write("\r\n");
73
w.write(msg);
74
w.flush();
75
s.close ();
76
srv.close ();
77
} catch (IOException e) {}
78
}
79
}
80
81
public class Finalizer {
82
public static void main (String args[]) {
83
try {
84
ServerSocket serversocket = new ServerSocket (0);
85
int port = serversocket.getLocalPort ();
86
XServer server = new XServer (serversocket);
87
server.start ();
88
Thread.sleep (2000);
89
URL url = new URL ("http://localhost:"+port+"/index.html");
90
URLConnection urlc = url.openConnection ();
91
urlc.connect ();
92
InputStream is = urlc.getInputStream ();
93
is = urlc.getInputStream ();
94
sink (is);
95
HttpURLConnection ht = (HttpURLConnection) urlc;
96
97
URLConnection url1 = url.openConnection ();
98
is = url1.getInputStream ();
99
100
ht = null; urlc = null;
101
System.gc();
102
System.runFinalization ();
103
104
sink (is);
105
106
System.out.println("Passed!");
107
} catch (IOException e) {
108
throw new RuntimeException("finalize method failure."+e);
109
} catch (InterruptedException ie) {
110
}
111
}
112
113
static void sink (InputStream is) {
114
int c;
115
byte [] b = new byte [1024];
116
try {
117
while ((c = is.read (b)) != -1);
118
} catch (Exception e) {
119
throw new RuntimeException("finalize method failure."+e);
120
}
121
}
122
}
123
124