diff options
author | Mark Wielaard <mark@klomp.org> | 2002-11-23 00:52:10 +0000 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2002-11-23 00:52:10 +0000 |
commit | 02330c9994a44e139aef939fe312baf5bd7eb5fc (patch) | |
tree | e37dd43fc2f8f0e3bb8b352eb3f3284948cd99b4 | |
parent | fd5947f40d6edce984768bfea186fed85d90f66b (diff) | |
download | classpath-02330c9994a44e139aef939fe312baf5bd7eb5fc.tar.gz |
* gnu/java/net/protocol/jar/JarURLConnection.java (get):
ZipFile.OPEN_DELETE not yet implemented.
* java/net/HttpURLConnection.java (getResponseVals): Only set
responseCode when not yet explicitly set by subclass.
* java/net/URLClassLoader.java (URLLoader.getManifest): Make default
return null.
(URLResource.getCertificates): Likewise
(RemoteURLLoader): New class.
(RemoteResource): Likewise.
(FileURLLoader.getManifest): No longer needed.
(FileResource.getCertificates): Likewise.
(addURL): Create either a FileURLLoader or a RemoteURLLoader.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | gnu/java/net/protocol/jar/JarURLConnection.java | 4 | ||||
-rw-r--r-- | java/net/HttpURLConnection.java | 51 | ||||
-rw-r--r-- | java/net/URLClassLoader.java | 116 |
4 files changed, 143 insertions, 43 deletions
@@ -1,5 +1,20 @@ 2002-11-22 Mark Wielaard <mark@klomp.org> + * gnu/java/net/protocol/jar/JarURLConnection.java (get): + ZipFile.OPEN_DELETE not yet implemented. + * java/net/HttpURLConnection.java (getResponseVals): Only set + responseCode when not yet explicitly set by subclass. + * java/net/URLClassLoader.java (URLLoader.getManifest): Make default + return null. + (URLResource.getCertificates): Likewise + (RemoteURLLoader): New class. + (RemoteResource): Likewise. + (FileURLLoader.getManifest): No longer needed. + (FileResource.getCertificates): Likewise. + (addURL): Create either a FileURLLoader or a RemoteURLLoader. + +2002-11-22 Mark Wielaard <mark@klomp.org> + * native/jni/java-net/java_net_InetAddress.c (lookupInaddrAny): Use Byte not Int arrays. (getHostByAddr): Likewise. diff --git a/gnu/java/net/protocol/jar/JarURLConnection.java b/gnu/java/net/protocol/jar/JarURLConnection.java index 4f947fc5c..d90a12a37 100644 --- a/gnu/java/net/protocol/jar/JarURLConnection.java +++ b/gnu/java/net/protocol/jar/JarURLConnection.java @@ -83,7 +83,9 @@ public class JarURLConnection extends java.net.JarURLConnection } fos.close(); // Always verify the Manifest, open read only and delete when done. - jf = new JarFile(f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); + // XXX ZipFile.OPEN_DELETE not yet implemented. + // jf = new JarFile(f, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE); + jf = new JarFile(f, true, ZipFile.OPEN_READ); } cache.put(url, jf); }finally{ diff --git a/java/net/HttpURLConnection.java b/java/net/HttpURLConnection.java index b717249e4..9446d69cd 100644 --- a/java/net/HttpURLConnection.java +++ b/java/net/HttpURLConnection.java @@ -464,31 +464,36 @@ public abstract class HttpURLConnection extends URLConnection connect(); gotResponseVals = true; - // Response is the first header received from the connection. - String respField = getHeaderField(0); - - if (respField == null || ! respField.startsWith("HTTP/")) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; - return; - } - int firstSpc, nextSpc; - firstSpc = respField.indexOf(' '); - nextSpc = respField.indexOf(' ', firstSpc + 1); - responseMessage = respField.substring(nextSpc + 1); - String codeStr = respField.substring(firstSpc + 1, nextSpc); - try + // If responseCode not yet explicitly set by subclass + if (responseCode == -1) { - responseCode = Integer.parseInt(codeStr); - } - catch (NumberFormatException e) - { - // Set to default values on failure. - responseCode = -1; - responseMessage = null; + // Response is the first header received from the connection. + String respField = getHeaderField(0); + + if (respField == null || ! respField.startsWith("HTTP/")) + { + // Set to default values on failure. + responseCode = -1; + responseMessage = null; + return; + } + + int firstSpc, nextSpc; + firstSpc = respField.indexOf(' '); + nextSpc = respField.indexOf(' ', firstSpc + 1); + responseMessage = respField.substring(nextSpc + 1); + String codeStr = respField.substring(firstSpc + 1, nextSpc); + try + { + responseCode = Integer.parseInt(codeStr); + } + catch (NumberFormatException e) + { + // Set to default values on failure. + responseCode = -1; + responseMessage = null; + } } } diff --git a/java/net/URLClassLoader.java b/java/net/URLClassLoader.java index 82438f912..986f0100c 100644 --- a/java/net/URLClassLoader.java +++ b/java/net/URLClassLoader.java @@ -111,10 +111,6 @@ import java.util.zip.ZipException; * * <li>The use of <code>URLStreamHandler</code>s has not been tested.</li> * - * <li>Loading remotely (e.g. http) only works when the target is a jar since - * the <code>FileURLLoader</code> currently only works on local directories. - * </li> - * * </ul> * </p> * @@ -211,7 +207,10 @@ public class URLClassLoader extends SecureClassLoader { * <code>Resource</code>s loaded by this <code>URLLoader</code> or * <code>null</code> there is no such <code>Manifest</code>. */ - abstract Manifest getManifest(); + Manifest getManifest() + { + return null; + } } /** @@ -249,7 +248,10 @@ public class URLClassLoader extends SecureClassLoader { * Returns <code>Certificates</code> associated with this * resource, or null when there are none. */ - abstract Certificate[] getCertificates(); + Certificate[] getCertificates() + { + return null; + } /** * Return a <code>URL</code> that can be used to access this resource. @@ -371,6 +373,91 @@ public class URLClassLoader extends SecureClassLoader { } /** + * Loader for remote directories. + */ + final static class RemoteURLLoader extends URLLoader + { + final private String protocol; + + RemoteURLLoader(URLClassLoader classloader, URL url) + { + super(classloader, url); + protocol = url.getProtocol(); + } + + /** + * Get a remote resource. + * Returns null if no such resource exists. + */ + Resource getResource(String name) + { + try + { + URL url = new URL(baseURL, name, + classloader.getURLStreamHandler(protocol)); + URLConnection connection = url.openConnection(); + + // Open the connection and check the stream + // just to be sure it exists. + int length = connection.getContentLength(); + InputStream stream = connection.getInputStream(); + + // We can do some extra checking if it is a http request + if (connection instanceof HttpURLConnection) + { + int response + = ((HttpURLConnection)connection).getResponseCode(); + if (response/100 != 2) + return null; + } + + if (stream != null) + return new RemoteResource(this, name, url, stream, length); + else + return null; + } + catch (IOException ioe) + { + return null; + } + } + } + + /** + * A resource from some remote location. + */ + final static class RemoteResource extends Resource + { + final private URL url; + final private InputStream stream; + final private int length; + + RemoteResource(RemoteURLLoader loader, String name, URL url, + InputStream stream, int length) + { + super(loader, name); + this.url = url; + this.stream = stream; + this.length = length; + } + + InputStream getInputStream() throws IOException + { + return stream; + } + + public int getLength() + { + return length; + } + + public URL getURL() + { + return url; + } + } + + /** * A <code>FileURLLoader</code> is a type of <code>URLLoader</code> * only loading from file url. */ @@ -394,12 +481,6 @@ public class URLClassLoader extends SecureClassLoader { else return null; } - - Manifest getManifest() - { - // Manifest not supported for FileURLLoader. - return null; - } } final static class FileResource extends Resource @@ -422,12 +503,6 @@ public class URLClassLoader extends SecureClassLoader { return (int)file.length(); } - public Certificate[] getCertificates() - { - // Certificates not supported for FileURLLoader. - return null; - } - public URL getURL() { try @@ -592,7 +667,10 @@ public class URLClassLoader extends SecureClassLoader { if (!file.endsWith("/")) // it's a jar url loader = new JarURLLoader(this, newUrl); else // it's a file url - loader = new FileURLLoader(this, newUrl); + if ("file".equals(newUrl.getProtocol())) + loader = new FileURLLoader(this, newUrl); + else + loader = new RemoteURLLoader(this, newUrl); //cache it urlloaders.put(newUrl, loader); |