2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2019-05-02 10:55:16 +00:00
|
|
|
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
2010-03-25 09:38:56 +00:00
|
|
|
* published by the Free Software Foundation.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 22:58:33 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 5052093
|
2015-05-28 17:54:48 +00:00
|
|
|
* @modules java.base/sun.net.www java.base/sun.net.www.protocol.file
|
2007-12-01 00:00:00 +00:00
|
|
|
* @library ../../../sun/net/www/httptest/
|
2012-09-07 14:30:17 +00:00
|
|
|
* @build HttpCallback TestHttpServer ClosedChannelList HttpTransaction
|
2007-12-01 00:00:00 +00:00
|
|
|
* @run main B5052093
|
|
|
|
* @summary URLConnection doesn't support large files
|
|
|
|
*/
|
|
|
|
import java.net.*;
|
|
|
|
import java.io.*;
|
|
|
|
import sun.net.www.protocol.file.FileURLConnection;
|
|
|
|
|
|
|
|
public class B5052093 implements HttpCallback {
|
2012-09-07 14:30:17 +00:00
|
|
|
private static TestHttpServer server;
|
2007-12-01 00:00:00 +00:00
|
|
|
private static long testSize = ((long) (Integer.MAX_VALUE)) + 2;
|
|
|
|
|
|
|
|
public static class LargeFile extends File {
|
|
|
|
public LargeFile() {
|
|
|
|
super("/dev/zero");
|
|
|
|
}
|
|
|
|
|
|
|
|
public long length() {
|
|
|
|
return testSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class LargeFileURLConnection extends FileURLConnection {
|
|
|
|
public LargeFileURLConnection(LargeFile f) throws IOException {
|
|
|
|
super(new URL("file:///dev/zero"), f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void request(HttpTransaction req) {
|
|
|
|
try {
|
|
|
|
req.setResponseHeader("content-length", Long.toString(testSize));
|
|
|
|
req.sendResponse(200, "OK");
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
2019-05-02 10:55:16 +00:00
|
|
|
InetAddress loopback = InetAddress.getLoopbackAddress();
|
|
|
|
server = new TestHttpServer(new B5052093(), 1, 10, loopback, 0);
|
2010-03-25 09:38:56 +00:00
|
|
|
try {
|
2019-05-02 10:55:16 +00:00
|
|
|
URL url = new URL("http://" + server.getAuthority() + "/foo");
|
2010-03-25 09:38:56 +00:00
|
|
|
URLConnection conn = url.openConnection();
|
|
|
|
int i = conn.getContentLength();
|
|
|
|
long l = conn.getContentLengthLong();
|
|
|
|
if (i != -1 || l != testSize) {
|
|
|
|
System.out.println("conn.getContentLength = " + i);
|
|
|
|
System.out.println("conn.getContentLengthLong = " + l);
|
|
|
|
System.out.println("testSize = " + testSize);
|
|
|
|
throw new RuntimeException("Wrong content-length from http");
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-03-25 09:38:56 +00:00
|
|
|
URLConnection fu = new LargeFileURLConnection(new LargeFile());
|
|
|
|
i = fu.getContentLength();
|
|
|
|
l = fu.getContentLengthLong();
|
|
|
|
if (i != -1 || l != testSize) {
|
|
|
|
System.out.println("fu.getContentLength = " + i);
|
|
|
|
System.out.println("fu.getContentLengthLong = " + l);
|
|
|
|
System.out.println("testSize = " + testSize);
|
|
|
|
throw new RuntimeException("Wrong content-length from file");
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
server.terminate();
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|