Commit 94f41586 by Michael Koch Committed by Michael Koch

2003-10-13 Michael Koch <konqueror@gmx.de>

	* java/net/JarURLConnection.java
	(jarFileURL): Added dcoumentation.
	(jarFileURLConnection): Reformated documentation.
	(entryName): Renamed from "element", documentation rewritten.
	(connectionCache): Renamed from "conn_cache", documentation
	reformated.
	(JarURLConnection): Check URL protocol.
	(getEntryName): Use entryName.
	(connect): Use connectionCache.
	(getInputStream): Use entryName, fixed comment.
	(getJarEntry): Use entryName.
	(getHeaders): Use entryName.
	* java/net/URLConnection.java
	(addRequestProperty): Fixed documentation.
	(setDefaultRequestProptery): Added comment that it does nothing since
	JDK 1.3.
	(getDefaultRequestProperty): Likewise.

From-SVN: r72420
parent 9917dcba
2003-10-13 Michael Koch <konqueror@gmx.de> 2003-10-13 Michael Koch <konqueror@gmx.de>
* java/net/JarURLConnection.java
(jarFileURL): Added dcoumentation.
(jarFileURLConnection): Reformated documentation.
(entryName): Renamed from "element", documentation rewritten.
(connectionCache): Renamed from "conn_cache", documentation
reformated.
(JarURLConnection): Check URL protocol.
(getEntryName): Use entryName.
(connect): Use connectionCache.
(getInputStream): Use entryName, fixed comment.
(getJarEntry): Use entryName.
(getHeaders): Use entryName.
* java/net/URLConnection.java
(addRequestProperty): Fixed documentation.
(setDefaultRequestProptery): Added comment that it does nothing since
JDK 1.3.
(getDefaultRequestProperty): Likewise.
2003-10-13 Michael Koch <konqueror@gmx.de>
* java/net/java/net/URLStreamHandlerFactory.java * java/net/java/net/URLStreamHandlerFactory.java
(createURLStreamHandler): Removed redundant "public" modifier. (createURLStreamHandler): Removed redundant "public" modifier.
* java/sql/DatabaseMetaData.java: * java/sql/DatabaseMetaData.java:
......
/* JarURLConnection.java -- Class for manipulating remote jar files /* JarURLConnection.java -- Class for manipulating remote jar files
Copyright (C) 1998 Free Software Foundation, Inc. Copyright (C) 1998, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath. This file is part of GNU Classpath.
...@@ -50,6 +50,7 @@ import java.util.jar.Manifest; ...@@ -50,6 +50,7 @@ import java.util.jar.Manifest;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import java.util.HashMap;
import java.util.Hashtable; import java.util.Hashtable;
import java.security.cert.Certificate; import java.security.cert.Certificate;
...@@ -80,19 +81,29 @@ import java.security.cert.Certificate; ...@@ -80,19 +81,29 @@ import java.security.cert.Certificate;
*/ */
public abstract class JarURLConnection extends URLConnection public abstract class JarURLConnection extends URLConnection
{ {
// three different ways to say the same thing /**
* This is the actual URL that points the remote jar file. This is parsed
* out of the jar URL by the constructor.
*/
private final URL jarFileURL; private final URL jarFileURL;
/** The connection to the jar file itself. A JarURLConnection /**
* can represent an entry in a jar file or an entire jar file. In * The connection to the jar file itself. A JarURLConnection
* either case this describes just the jar file itself. */ * can represent an entry in a jar file or an entire jar file. In
* either case this describes just the jar file itself.
*/
protected URLConnection jarFileURLConnection; protected URLConnection jarFileURLConnection;
// If this is a connection to a jar file element this is set, otherwise null. /**
private final String element; * This is the jar file "entry name" or portion after the "!/" in the
* URL which represents the pathname inside the actual jar file.
*/
private final String entryName;
// Cached JarURLConnection's /**
static Hashtable conn_cache = new Hashtable(); * Cached JarURLConnection objects .
*/
static HashMap connectionCache = new HashMap();
/** /**
* Creates a JarURLConnection from an URL object * Creates a JarURLConnection from an URL object
...@@ -108,6 +119,9 @@ public abstract class JarURLConnection extends URLConnection ...@@ -108,6 +119,9 @@ public abstract class JarURLConnection extends URLConnection
{ {
super (url); super (url);
if (!url.getProtocol().equals ("jar"))
throw new MalformedURLException (url + ": Not jar protocol.");
String spec = url.getFile(); String spec = url.getFile();
int bang = spec.indexOf ("!/"); int bang = spec.indexOf ("!/");
if (bang == -1) if (bang == -1)
...@@ -116,8 +130,8 @@ public abstract class JarURLConnection extends URLConnection ...@@ -116,8 +130,8 @@ public abstract class JarURLConnection extends URLConnection
// Extract the url for the jar itself. // Extract the url for the jar itself.
jarFileURL = new URL (spec.substring (0, bang)); jarFileURL = new URL (spec.substring (0, bang));
// Get the name of the element, if any. // Get the name of the entry, if any.
element = (spec.length() == (bang + 2) ? null : spec.substring (bang + 2)); entryName = spec.length() == (bang + 2) ? null : spec.substring (bang + 2);
} }
/** /**
...@@ -140,7 +154,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -140,7 +154,7 @@ public abstract class JarURLConnection extends URLConnection
*/ */
public String getEntryName () public String getEntryName ()
{ {
return element; return entryName;
} }
public synchronized void connect() throws IOException public synchronized void connect() throws IOException
...@@ -151,14 +165,14 @@ public abstract class JarURLConnection extends URLConnection ...@@ -151,14 +165,14 @@ public abstract class JarURLConnection extends URLConnection
if (getUseCaches()) if (getUseCaches())
{ {
jarFileURLConnection = (URLConnection) conn_cache.get (jarFileURL); jarFileURLConnection = (URLConnection) connectionCache.get (jarFileURL);
if (jarFileURLConnection == null) if (jarFileURLConnection == null)
{ {
jarFileURLConnection = jarFileURL.openConnection (); jarFileURLConnection = jarFileURL.openConnection ();
jarFileURLConnection.setUseCaches (true); jarFileURLConnection.setUseCaches (true);
jarFileURLConnection.connect (); jarFileURLConnection.connect ();
conn_cache.put (jarFileURL, jarFileURLConnection); connectionCache.put (jarFileURL, jarFileURLConnection);
} }
} }
else else
...@@ -178,7 +192,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -178,7 +192,7 @@ public abstract class JarURLConnection extends URLConnection
if (! doInput) if (! doInput)
throw new ProtocolException("Can't open InputStream if doInput is false"); throw new ProtocolException("Can't open InputStream if doInput is false");
if (element == null) if (entryName == null)
{ {
// This is a JarURLConnection for the entire jar file. // This is a JarURLConnection for the entire jar file.
...@@ -187,7 +201,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -187,7 +201,7 @@ public abstract class JarURLConnection extends URLConnection
return new JarInputStream(jar_is); return new JarInputStream(jar_is);
} }
// Reaching this point, we're looking for an element of a jar file. // Reaching this point, we're looking for an entry of a jar file.
JarFile jarfile = null; JarFile jarfile = null;
...@@ -195,7 +209,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -195,7 +209,7 @@ public abstract class JarURLConnection extends URLConnection
{ {
jarfile = getJarFile (); jarfile = getJarFile ();
} }
catch (java.io.IOException x) catch (IOException x)
{ {
/* ignore */ /* ignore */
} }
...@@ -203,7 +217,8 @@ public abstract class JarURLConnection extends URLConnection ...@@ -203,7 +217,8 @@ public abstract class JarURLConnection extends URLConnection
if (jarfile != null) if (jarfile != null)
{ {
// this is the easy way... // this is the easy way...
ZipEntry entry = jarfile.getEntry(element); ZipEntry entry = jarfile.getEntry (entryName);
if (entry != null) if (entry != null)
return jarfile.getInputStream (entry); return jarfile.getInputStream (entry);
else else
...@@ -220,7 +235,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -220,7 +235,7 @@ public abstract class JarURLConnection extends URLConnection
ent != null; ent != null;
ent = zis.getNextEntry ()) ent = zis.getNextEntry ())
{ {
if (element.equals (ent.getName ())) if (entryName.equals (ent.getName()))
{ {
int size = (int)ent.getSize(); int size = (int)ent.getSize();
byte[] data = new byte[size]; byte[] data = new byte[size];
...@@ -244,7 +259,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -244,7 +259,7 @@ public abstract class JarURLConnection extends URLConnection
{ {
JarFile jarfile = null; JarFile jarfile = null;
if (element == null) if (entryName == null)
return null; return null;
if (! doInput) if (! doInput)
...@@ -269,7 +284,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -269,7 +284,7 @@ public abstract class JarURLConnection extends URLConnection
ent != null; ent != null;
ent = zis.getNextEntry ()) ent = zis.getNextEntry ())
{ {
if (element.equals (ent.getName ())) if (entryName.equals (ent.getName()))
{ {
return new JarEntry (ent); return new JarEntry (ent);
} }
...@@ -278,7 +293,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -278,7 +293,7 @@ public abstract class JarURLConnection extends URLConnection
else else
{ {
return jarfile.getJarEntry (element); return jarfile.getJarEntry (entryName);
} }
return null; return null;
...@@ -398,7 +413,7 @@ public abstract class JarURLConnection extends URLConnection ...@@ -398,7 +413,7 @@ public abstract class JarURLConnection extends URLConnection
// Add the only header we know about right now: Content-length. // Add the only header we know about right now: Content-length.
long len = -1; long len = -1;
if (element == null) if (entryName == null)
if (jarFileURLConnection != null) if (jarFileURLConnection != null)
len = jarFileURLConnection.getContentLength (); len = jarFileURLConnection.getContentLength ();
else else
......
...@@ -726,7 +726,7 @@ public abstract class URLConnection ...@@ -726,7 +726,7 @@ public abstract class URLConnection
/** /**
* Adds a new request property by a key/value pair. * Adds a new request property by a key/value pair.
* This method does not overwrite* existing properties with the same key. * This method does not overwrite existing properties with the same key.
* *
* @param key Key of the property to add * @param key Key of the property to add
* @param value Value of the Property to add * @param value Value of the Property to add
...@@ -800,14 +800,14 @@ public abstract class URLConnection ...@@ -800,14 +800,14 @@ public abstract class URLConnection
* @param key The request property name the default is being set for * @param key The request property name the default is being set for
* @param value The value to set the default to * @param value The value to set the default to
* *
* @deprecated 1.3 The method setRequestProperty should be used instead * @deprecated 1.3 The method setRequestProperty should be used instead.
* This method does nothing now.
* *
* @see URLConnectionr#setRequestProperty(String key, String value) * @see URLConnectionr#setRequestProperty(String key, String value)
*/ */
public static void setDefaultRequestProperty(String key, String value) public static void setDefaultRequestProperty (String key, String value)
{ {
// Do nothing unless overridden by subclasses that support setting // This method does nothing since JDK 1.3.
// default request properties.
} }
/** /**
...@@ -819,13 +819,14 @@ public abstract class URLConnection ...@@ -819,13 +819,14 @@ public abstract class URLConnection
* *
* @return The value of the default property or null if not available * @return The value of the default property or null if not available
* *
* @deprecated 1.3 The method getRequestProperty should be used instead * @deprecated 1.3 The method getRequestProperty should be used instead.
* This method does nothing now.
* *
* @see URLConnection#getRequestProperty(String key) * @see URLConnection#getRequestProperty(String key)
*/ */
public static String getDefaultRequestProperty(String key) public static String getDefaultRequestProperty(String key)
{ {
// Overridden by subclasses that support default request properties. // This method does nothing since JDK 1.3.
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment