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/TestCache.java
41161 views
1
/*
2
* Copyright (c) 2010, 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.net.*;
25
import java.io.*;
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.io.OutputStream;
29
import java.io.FileInputStream;
30
import java.io.FileOutputStream;
31
import java.io.BufferedInputStream;
32
import java.io.ByteArrayInputStream;
33
import java.io.PrintStream;
34
import java.io.InputStream;
35
import java.io.File;
36
import java.net.CacheRequest;
37
import java.net.CacheResponse;
38
import java.net.ResponseCache;
39
import java.net.URI;
40
import java.net.URL;
41
import java.net.URLConnection;
42
import java.util.ArrayList;
43
import java.util.HashMap;
44
import java.util.Map;
45
import java.util.List;
46
import java.util.Iterator;
47
import java.util.StringTokenizer;
48
import java.util.jar.JarInputStream;
49
import java.util.jar.JarFile;
50
import java.security.AccessController;
51
import java.security.PrivilegedAction;
52
import java.security.PrivilegedExceptionAction;
53
import java.security.PrivilegedActionException;
54
import java.security.Principal;
55
import java.security.cert.Certificate;
56
import javax.net.ssl.SSLPeerUnverifiedException;
57
58
public class TestCache extends java.net.ResponseCache {
59
private boolean inCacheHandler = false;
60
private boolean _downloading = false;
61
62
public static volatile boolean fail = false;
63
64
public static void reset() {
65
// Set system wide cache handler
66
System.out.println("install deploy cache handler");
67
ResponseCache.setDefault(new TestCache());
68
}
69
70
public synchronized CacheResponse get(final URI uri, String rqstMethod,
71
Map requestHeaders) throws IOException {
72
System.out.println("get: " + uri);
73
Thread.currentThread().dumpStack();
74
return null;
75
}
76
77
public synchronized CacheRequest put(URI uri, URLConnection conn)
78
throws IOException {
79
System.out.println("put: " + uri);
80
Thread.currentThread().dumpStack();
81
URL url = uri.toURL();
82
return new DeployCacheRequest(url, conn);
83
84
}
85
}
86
87
class DeployByteArrayOutputStream extends java.io.ByteArrayOutputStream {
88
89
private URL _url;
90
private URLConnection _conn;
91
92
DeployByteArrayOutputStream(URL url, URLConnection conn) {
93
_url = url;
94
_conn = conn;
95
}
96
97
98
public void close() throws IOException {
99
100
System.out.println("contentLength: " + _conn.getContentLength());
101
System.out.println("byte array size: " + size());
102
if ( _conn.getContentLength() == size()) {
103
System.out.println("correct content length");
104
} else {
105
System.out.println("wrong content length");
106
System.out.println("TEST FAILED");
107
TestCache.fail = true;
108
}
109
super.close();
110
}
111
}
112
113
class DeployCacheRequest extends java.net.CacheRequest {
114
115
private URL _url;
116
private URLConnection _conn;
117
private boolean _downloading = false;
118
119
DeployCacheRequest(URL url, URLConnection conn) {
120
System.out.println("DeployCacheRequest ctor for: " + url);
121
_url = url;
122
_conn = conn;
123
}
124
125
public void abort() {
126
System.out.println("abort called");
127
}
128
129
public OutputStream getBody() throws IOException {
130
System.out.println("getBody called");
131
return new DeployByteArrayOutputStream(_url, _conn);
132
}
133
}
134
135