Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/6550798/test.java
41161 views
1
/*
2
* Copyright (c) 2010, 2019, 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
/**
25
* @test
26
* @bug 6550798
27
* @library /test/lib
28
* @summary Using InputStream.skip with ResponseCache will cause partial data to be cached
29
* @modules jdk.httpserver
30
* @run main/othervm test
31
*/
32
33
import java.net.*;
34
import com.sun.net.httpserver.*;
35
import java.io.*;
36
37
import jdk.test.lib.net.URIBuilder;
38
39
public class test {
40
41
final static int LEN = 16 * 1024;
42
43
public static void main(String[] args) throws Exception {
44
45
TestCache.reset();
46
InetAddress loopback = InetAddress.getLoopbackAddress();
47
HttpServer s = HttpServer.create(new InetSocketAddress(loopback, 0), 10);
48
s.createContext("/", new HttpHandler() {
49
public void handle(HttpExchange e) {
50
try {
51
byte[] buf = new byte [LEN];
52
OutputStream o = e.getResponseBody();
53
e.sendResponseHeaders(200, LEN);
54
o.write(buf);
55
e.close();
56
} catch (IOException ex) {
57
ex.printStackTrace();
58
TestCache.fail = true;
59
}
60
}
61
});
62
s.start();
63
64
System.out.println("http request with cache hander");
65
URL u = URIBuilder.newBuilder()
66
.scheme("http")
67
.loopback()
68
.port(s.getAddress().getPort())
69
.path("/f")
70
.toURL();
71
System.out.println("URL: " + u);
72
URLConnection conn = u.openConnection();
73
74
InputStream is = null;
75
try {
76
// this calls into TestCache.get
77
byte[] buf = new byte[8192];
78
is = new BufferedInputStream(conn.getInputStream());
79
80
is.skip(1000);
81
82
while (is.read(buf) != -1) {
83
}
84
} finally {
85
if (is != null) {
86
// this calls into TestCache.put
87
// TestCache.put will check if the resource
88
// should be cached
89
is.close();
90
}
91
s.stop(0);
92
}
93
94
if (TestCache.fail) {
95
System.out.println("TEST FAILED");
96
throw new RuntimeException();
97
} else {
98
System.out.println("TEST OK");
99
}
100
}
101
}
102
103