Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/net/URLConnection/SetIfModifiedSince.java
38811 views
1
/*
2
* Copyright (c) 2000, 2011, 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 4397096
26
* @run main/othervm SetIfModifiedSince
27
* @summary setIfModifiedSince() of HttpURLConnection sets invalid date of default locale
28
*/
29
30
import java.net.*;
31
import java.io.*;
32
import java.util.*;
33
34
public class SetIfModifiedSince {
35
36
static class XServer extends Thread {
37
ServerSocket srv;
38
Socket s;
39
InputStream is;
40
OutputStream os;
41
42
XServer (ServerSocket s) {
43
srv = s;
44
}
45
46
Socket getSocket () {
47
return (s);
48
}
49
50
public void run() {
51
try {
52
String x;
53
s = srv.accept ();
54
is = s.getInputStream ();
55
BufferedReader r = new BufferedReader(new InputStreamReader(is));
56
os = s.getOutputStream ();
57
while ((x=r.readLine()) != null) {
58
String header = "If-Modified-Since: ";
59
if (x.startsWith(header)) {
60
if (x.charAt(header.length()) == '?') {
61
s.close ();
62
srv.close (); // or else the HTTPURLConnection will retry
63
throw new RuntimeException
64
("Invalid HTTP date specification");
65
}
66
break;
67
}
68
}
69
s.close ();
70
srv.close (); // or else the HTTPURLConnection will retry
71
} catch (IOException e) {}
72
}
73
}
74
75
public static void main (String[] args) {
76
Locale reservedLocale = Locale.getDefault();
77
try {
78
Locale.setDefault(Locale.JAPAN);
79
ServerSocket serversocket = new ServerSocket (0);
80
int port = serversocket.getLocalPort ();
81
XServer server = new XServer (serversocket);
82
server.start ();
83
Thread.sleep (2000);
84
URL url = new URL ("http://localhost:"+port+"/index.html");
85
URLConnection urlc = url.openConnection ();
86
urlc.setIfModifiedSince (10000000);
87
InputStream is = urlc.getInputStream ();
88
int i=0, c;
89
Thread.sleep (5000);
90
} catch (Exception e) {
91
} finally {
92
// restore the reserved locale
93
Locale.setDefault(reservedLocale);
94
}
95
96
}
97
}
98
99