+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
/* 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.
import java.util.zip.ZipEntry;
import java.util.Map;
import java.util.Vector;
+import java.util.HashMap;
import java.util.Hashtable;
import java.security.cert.Certificate;
*/
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;
- /** The connection to the jar file itself. A JarURLConnection
- * can represent an entry in a jar file or an entire jar file. In
- * either case this describes just the jar file itself. */
+ /**
+ * The connection to the jar file itself. A JarURLConnection
+ * 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;
- // 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
{
super (url);
+ if (!url.getProtocol().equals ("jar"))
+ throw new MalformedURLException (url + ": Not jar protocol.");
+
String spec = url.getFile();
int bang = spec.indexOf ("!/");
if (bang == -1)
// Extract the url for the jar itself.
jarFileURL = new URL (spec.substring (0, bang));
- // Get the name of the element, if any.
- element = (spec.length() == (bang + 2) ? null : spec.substring (bang + 2));
+ // Get the name of the entry, if any.
+ entryName = spec.length() == (bang + 2) ? null : spec.substring (bang + 2);
}
/**
*/
public String getEntryName ()
{
- return element;
+ return entryName;
}
public synchronized void connect() throws IOException
if (getUseCaches())
{
- jarFileURLConnection = (URLConnection) conn_cache.get (jarFileURL);
+ jarFileURLConnection = (URLConnection) connectionCache.get (jarFileURL);
if (jarFileURLConnection == null)
{
jarFileURLConnection = jarFileURL.openConnection ();
jarFileURLConnection.setUseCaches (true);
jarFileURLConnection.connect ();
- conn_cache.put (jarFileURL, jarFileURLConnection);
+ connectionCache.put (jarFileURL, jarFileURLConnection);
}
}
else
if (! doInput)
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.
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 = getJarFile ();
}
- catch (java.io.IOException x)
+ catch (IOException x)
{
/* ignore */
}
if (jarfile != null)
{
// this is the easy way...
- ZipEntry entry = jarfile.getEntry(element);
+ ZipEntry entry = jarfile.getEntry (entryName);
+
if (entry != null)
return jarfile.getInputStream (entry);
else
ent != null;
ent = zis.getNextEntry ())
{
- if (element.equals (ent.getName ()))
+ if (entryName.equals (ent.getName()))
{
int size = (int)ent.getSize();
byte[] data = new byte[size];
{
JarFile jarfile = null;
- if (element == null)
+ if (entryName == null)
return null;
if (! doInput)
ent != null;
ent = zis.getNextEntry ())
{
- if (element.equals (ent.getName ()))
+ if (entryName.equals (ent.getName()))
{
return new JarEntry (ent);
}
else
{
- return jarfile.getJarEntry (element);
+ return jarfile.getJarEntry (entryName);
}
return null;
// Add the only header we know about right now: Content-length.
long len = -1;
- if (element == null)
+ if (entryName == null)
if (jarFileURLConnection != null)
len = jarFileURLConnection.getContentLength ();
else
/**
* 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 value Value of the Property to add
* @param key The request property name the default is being set for
* @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)
*/
- 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
- // default request properties.
+ // This method does nothing since JDK 1.3.
}
/**
*
* @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)
*/
public static String getDefaultRequestProperty(String key)
{
- // Overridden by subclasses that support default request properties.
+ // This method does nothing since JDK 1.3.
return null;
}