Index: java/net/ContentHandler.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/ContentHandler.java,v
retrieving revision 1.9
diff -u -r1.9 ContentHandler.java
--- java/net/ContentHandler.java 24 May 2003 04:37:18 -0000 1.9
+++ java/net/ContentHandler.java 8 Apr 2004 16:53:13 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -47,11 +47,11 @@
/**
* This is an abstract class that is the superclass for classes that read
- * objects from URL's. Calling the getContent()
method in the
- * URL
class or the URLConnection
class will cause
- * an instance of a subclass of ContentHandler
to be created for
- * the MIME type of the object being downloaded from the URL. Thus, this
- * class is seldom needed by applications/applets directly, but only
+ * objects from URL's. Calling the getContent()
method in the
+ * URL
class or the URLConnection
class will cause
+ * an instance of a subclass of ContentHandler
to be created for
+ * the MIME type of the object being downloaded from the URL. Thus, this
+ * class is seldom needed by applications/applets directly, but only
* indirectly through methods in other classes.
*
* @author Aaron M. Renn (address@hidden)
@@ -66,8 +66,8 @@
/**
* Default, no-argument constructor.
*/
- public ContentHandler()
- {
+ public ContentHandler()
+ {
}
/*
@@ -75,10 +75,10 @@
*/
/**
- * This method reads from the InputStream
of the passed in URL
- * connection and uses the data downloaded to create an Object
- * represening the content. For example, if the URL is pointing to a GIF
- * file, this method might return an Image
object. This method
+ * This method reads from the InputStream
of the passed in URL
+ * connection and uses the data downloaded to create an Object
+ * represening the content. For example, if the URL is pointing to a GIF
+ * file, this method might return an Image
object. This method
* must be implemented by subclasses.
*
* @param urlc A URLConnection
object to read data from.
@@ -87,16 +87,16 @@
*
* @exception IOException If an error occurs
*/
- public abstract Object getContent(URLConnection urlc)
+ public abstract Object getContent(URLConnection urlc)
throws IOException;
/**
* This method reads from the InputStream
of the passed in URL
* connection and uses the data downloaded to create an Object
- * represening the content. For example, if the URL is pointing to a GIF
- * file, this method might return an Image
object. This method
+ * represening the content. For example, if the URL is pointing to a GIF
+ * file, this method might return an Image
object. This method
* must be implemented by subclasses. This method uses the list of
- * supplied classes as candidate types. If the data read doesn't match
+ * supplied classes as candidate types. If the data read doesn't match
* any of the supplied type, null
is returned.
*
* @param urlc A URLConnection
object to read data from.
@@ -113,15 +113,14 @@
public Object getContent(URLConnection urlc, Class[] classes)
throws IOException
{
- Object obj = getContent (urlc);
+ Object obj = getContent(urlc);
for (int i = 0; i < classes.length; i++)
{
- if (classes [i].isInstance (obj))
- return obj;
+ if (classes[i].isInstance(obj))
+ return obj;
}
return null;
}
-
} // class ContentHandler
Index: java/net/ContentHandlerFactory.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/ContentHandlerFactory.java,v
retrieving revision 1.10
diff -u -r1.10 ContentHandlerFactory.java
--- java/net/ContentHandlerFactory.java 12 Oct 2003 15:35:01 -0000 1.10
+++ java/net/ContentHandlerFactory.java 8 Apr 2004 16:53:13 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,18 +35,17 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
+
/**
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
* Status: Believed complete and correct.
*/
-
/**
- * This interface maps MIME types to ContentHandler
objects.
- * It consists of one method that, when passed a MIME type, returns a
+ * This interface maps MIME types to ContentHandler
objects.
+ * It consists of one method that, when passed a MIME type, returns a
* handler for that type.
*
* @author Aaron M. Renn (address@hidden)
@@ -63,6 +62,4 @@
* @return The ContentHandler
for the passed in MIME type
*/
ContentHandler createContentHandler(String mimeType);
-
} // interface ContentHandlerFactory
-
Index: java/net/Inet4Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet4Address.java,v
retrieving revision 1.8
diff -u -r1.8 Inet4Address.java
--- java/net/Inet4Address.java 15 Nov 2003 22:41:54 -0000 1.8
+++ java/net/Inet4Address.java 8 Apr 2004 16:53:13 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,12 +35,12 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import java.io.ObjectStreamException;
import java.util.Arrays;
+
/**
* @author Michael Koch
* @date August 3, 2002.
@@ -53,7 +53,6 @@
* RFC 2365 (http://www.ietf.org/rfc/rfc2365.txt)
* Status: Believed complete and correct.
*/
-
public final class Inet4Address extends InetAddress
{
static final long serialVersionUID = 3286316764910316507L;
@@ -61,20 +60,20 @@
/**
* needed for serialization
*/
- private Object writeReplace () throws ObjectStreamException
+ private Object writeReplace() throws ObjectStreamException
{
- return new InetAddress (addr, hostName);
+ return new InetAddress(addr, hostName);
}
/**
* Creates a Inet4Address
- *
+ *
* @param addr The IP address
* @param host The Hostname
*/
Inet4Address(byte[] addr, String host)
{
- super (addr, host);
+ super(addr, host);
}
/**
@@ -82,37 +81,37 @@
*
* @since 1.1
*/
- public boolean isMulticastAddress ()
+ public boolean isMulticastAddress()
{
- return (addr [0] & 0xF0) == 0xE0;
+ return (addr[0] & 0xF0) == 0xE0;
}
-
+
/**
* Checks if this address is a loopback address
*/
- public boolean isLoopbackAddress ()
+ public boolean isLoopbackAddress()
{
- return addr [0] == 0x7F;
+ return addr[0] == 0x7F;
}
-
+
/**
* Checks if this address is a wildcard address
*
* @since 1.4
*/
- public boolean isAnyLocalAddress ()
+ public boolean isAnyLocalAddress()
{
byte[] anylocal = { 0, 0, 0, 0 };
-
+
return Arrays.equals(addr, anylocal);
}
/**
* Checks if this address is a link local address
- *
+ *
* @since 1.4
*/
- public boolean isLinkLocalAddress ()
+ public boolean isLinkLocalAddress()
{
// XXX: This seems to not exist with IPv4 addresses
return false;
@@ -120,36 +119,36 @@
/**
* Checks if this address is a site local address
- *
+ *
* @since 1.4
*/
- public boolean isSiteLocalAddress ()
+ public boolean isSiteLocalAddress()
{
// 10.0.0.0/8
- if (addr [0] == 0x0A)
+ if (addr[0] == 0x0A)
return true;
// XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:
// it says 172.16.0.0 - 172.255.255.255 are site local addresses
//
// 172.16.0.0/12
- if (addr [0] == 0xAC && (addr [1] & 0xF0) == 0x01)
+ if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01)
return true;
// 192.168.0.0/16
- if (addr [0] == 0xC0 && addr [1] == 0xA8)
+ if (addr[0] == 0xC0 && addr[1] == 0xA8)
return true;
-
+
// XXX: Do we need to check more addresses here ?
return false;
}
/**
* Checks if this multicast address has global scope
- *
+ *
* @since 1.4
*/
- public boolean isMCGlobal ()
+ public boolean isMCGlobal()
{
// XXX: This seems to net exist with IPv4 addresses
return false;
@@ -157,120 +156,118 @@
/**
* Checks if this multicast address has node scope
- *
+ *
* @since 1.4
*/
- public boolean isMCNodeLocal ()
+ public boolean isMCNodeLocal()
{
// XXX: This seems to net exist with IPv4 addresses
return false;
}
-
+
/**
* Checks if this multicast address has link scope
- *
+ *
* @since 1.4
*/
- public boolean isMCLinkLocal ()
+ public boolean isMCLinkLocal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (addr [0] == 0xE0)
- && (addr [1] == 0x00)
- && (addr [2] == 0x00);
+
+ return (addr[0] == 0xE0) && (addr[1] == 0x00) && (addr[2] == 0x00);
}
-
+
/**
* Checks if this multicast address has site scope
- *
+ *
* @since 1.4
*/
- public boolean isMCSiteLocal ()
+ public boolean isMCSiteLocal()
{
// XXX: This seems to net exist with IPv4 addresses
return false;
}
-
+
/**
* Checks if this multicast address has organization scope
- *
+ *
* @since 1.4
*/
- public boolean isMCOrgLocal ()
+ public boolean isMCOrgLocal()
{
// XXX: This seems to net exist with IPv4 addresses
return false;
}
-
+
/**
* Returns the address of the current instance
*/
- public byte[] getAddress ()
+ public byte[] getAddress()
{
return addr;
}
-
+
/**
* Returns the address as string
- *
+ *
* @since 1.0.2
*/
- public String getHostAddress ()
+ public String getHostAddress()
{
- StringBuffer sbuf = new StringBuffer (40);
+ StringBuffer sbuf = new StringBuffer(40);
int len = addr.length;
int i = 0;
-
- for ( ; ; )
+
+ for (;;)
{
- sbuf.append (addr [i] & 0xFF);
+ sbuf.append(addr[i] & 0xFF);
i++;
-
+
if (i == len)
break;
-
- sbuf.append ('.');
+
+ sbuf.append('.');
}
-
- return sbuf.toString ();
+
+ return sbuf.toString();
}
-
+
/**
* Computes the hashcode of the instance
*/
- public int hashCode ()
+ public int hashCode()
{
int hash = 0;
int len = addr.length;
int i = len > 4 ? len - 4 : 0;
-
- for ( ; i < len; i++)
- hash = (hash << 8) | (addr [i] & 0xFF);
-
+
+ for (; i < len; i++)
+ hash = (hash << 8) | (addr[i] & 0xFF);
+
return hash;
}
-
+
/**
* Compare the current Inet4Address instance with obj
- *
+ *
* @param obj Object to compare with
*/
- public boolean equals (Object obj)
+ public boolean equals(Object obj)
{
if (! (obj instanceof InetAddress))
return false;
-
+
byte[] addr1 = addr;
byte[] addr2 = ((InetAddress) obj).addr;
-
+
if (addr1.length != addr2.length)
return false;
-
- for (int i = addr1.length; --i >= 0; )
- if (addr1 [i] != addr2 [i])
- return false;
-
+
+ for (int i = addr1.length; --i >= 0;)
+ if (addr1[i] != addr2[i])
+ return false;
+
return true;
}
} // class Inet4Address
Index: java/net/Inet6Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet6Address.java,v
retrieving revision 1.5
diff -u -r1.5 Inet6Address.java
--- java/net/Inet6Address.java 15 Nov 2003 22:41:54 -0000 1.5
+++ java/net/Inet6Address.java 8 Apr 2004 16:53:14 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,11 +35,11 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import java.util.Arrays;
+
/**
* @author Michael Koch
* @date August 3, 2002.
@@ -50,7 +50,6 @@
* RFC 1884 (http://www.ietf.org/rfc/rfc1884.txt)
* Status: Believed complete and correct.
*/
-
public final class Inet6Address extends InetAddress
{
static final long serialVersionUID = 6880410070516793377L;
@@ -59,213 +58,210 @@
* Needed for serialization
*/
byte[] ipaddress;
-
+
/**
* Create an Inet6Address object
*
* @param addr The IP address
* @param host The hostname
*/
- Inet6Address (byte[] addr, String host)
+ Inet6Address(byte[] addr, String host)
{
- super (addr, host);
+ super(addr, host);
this.ipaddress = addr;
}
/**
* Utility routine to check if the InetAddress is an IP multicast address
- *
+ *
* @since 1.1
*/
- public boolean isMulticastAddress ()
+ public boolean isMulticastAddress()
{
- return ipaddress [0] == 0xFF;
+ return ipaddress[0] == 0xFF;
}
-
+
/**
* Utility routine to check if the InetAddress in a wildcard address
- *
+ *
* @since 1.4
*/
- public boolean isAnyLocalAddress ()
+ public boolean isAnyLocalAddress()
{
- byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0 };
-
+ byte[] anylocal = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+
return Arrays.equals(ipaddress, anylocal);
}
-
+
/**
* Utility routine to check if the InetAddress is a loopback address
- *
+ *
* @since 1.4
*/
- public boolean isLoopbackAddress ()
+ public boolean isLoopbackAddress()
{
- byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 1 };
-
+ byte[] loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+
return Arrays.equals(ipaddress, loopback);
}
/**
* Utility routine to check if the InetAddress is an link local address
- *
+ *
* @since 1.4
*/
- public boolean isLinkLocalAddress ()
+ public boolean isLinkLocalAddress()
{
- return ipaddress [0] == 0xFA;
+ return ipaddress[0] == 0xFA;
}
/**
* Utility routine to check if the InetAddress is a site local address
- *
+ *
* @since 1.4
*/
- public boolean isSiteLocalAddress ()
+ public boolean isSiteLocalAddress()
{
- return ipaddress [0] == 0xFB;
+ return ipaddress[0] == 0xFB;
}
/**
* Utility routine to check if the multicast address has global scope
- *
+ *
* @since 1.4
*/
- public boolean isMCGlobal ()
+ public boolean isMCGlobal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (ipaddress [1] & 0x0F) == 0xE;
+
+ return (ipaddress[1] & 0x0F) == 0xE;
}
/**
* Utility routine to check if the multicast address has node scope
- *
+ *
* @since 1.4
*/
- public boolean isMCNodeLocal ()
+ public boolean isMCNodeLocal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (ipaddress [1] & 0x0F) == 0x1;
+
+ return (ipaddress[1] & 0x0F) == 0x1;
}
/**
* Utility routine to check if the multicast address has link scope
- *
+ *
* @since 1.4
*/
- public boolean isMCLinkLocal ()
+ public boolean isMCLinkLocal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (ipaddress [1] & 0x0F) == 0x2;
+
+ return (ipaddress[1] & 0x0F) == 0x2;
}
/**
* Utility routine to check if the multicast address has site scope
- *
+ *
* @since 1.4
*/
- public boolean isMCSiteLocal ()
+ public boolean isMCSiteLocal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (ipaddress [1] & 0x0F) == 0x5;
+
+ return (ipaddress[1] & 0x0F) == 0x5;
}
/**
* Utility routine to check if the multicast address has organization scope
- *
+ *
* @since 1.4
*/
- public boolean isMCOrgLocal ()
+ public boolean isMCOrgLocal()
{
- if (!isMulticastAddress ())
+ if (! isMulticastAddress())
return false;
-
- return (ipaddress [1] & 0x0F) == 0x8;
+
+ return (ipaddress[1] & 0x0F) == 0x8;
}
-
+
/**
* Returns the raw IP address of this InetAddress object. The result is in
* network byte order: the highest order byte of the address is i
* n getAddress()[0]
*/
- public byte[] getAddress ()
+ public byte[] getAddress()
{
return ipaddress;
}
-
+
/**
* Returns the IP address string in textual presentation
*/
- public String getHostAddress ()
+ public String getHostAddress()
{
- StringBuffer sbuf = new StringBuffer (40);
+ StringBuffer sbuf = new StringBuffer(40);
for (int i = 0; i < 16; i += 2)
{
- int x = ((ipaddress [i] & 0xFF) << 8) | (ipaddress [i + 1] & 0xFF);
- boolean empty = sbuf.length () == 0;
-
- if (empty)
- {
- if (i > 0)
- sbuf.append ("::");
- }
- else
- sbuf.append (':');
+ int x = ((ipaddress[i] & 0xFF) << 8) | (ipaddress[i + 1] & 0xFF);
+ boolean empty = sbuf.length() == 0;
+
+ if (empty)
+ {
+ if (i > 0)
+ sbuf.append("::");
+ }
+ else
+ sbuf.append(':');
- if (x != 0 || i >= 14)
- sbuf.append (Integer.toHexString (x));
+ if (x != 0 || i >= 14)
+ sbuf.append(Integer.toHexString(x));
}
-
- return sbuf.toString ();
+
+ return sbuf.toString();
}
/**
* Returns a hashcode for this IP address
*/
- public int hashCode ()
+ public int hashCode()
{
- return super.hashCode ();
+ return super.hashCode();
}
-
+
/**
* Compares this object against the specified object
*/
- public boolean equals (Object obj)
+ public boolean equals(Object obj)
{
if (! (obj instanceof Inet6Address))
return false;
Inet6Address tmp = (Inet6Address) obj;
- return super.equals (tmp)
- && this.ipaddress == tmp.ipaddress;
+ return super.equals(tmp) && this.ipaddress == tmp.ipaddress;
}
-
+
/**
* Utility routine to check if the InetAddress is an
* IPv4 compatible IPv6 address
*
* @since 1.4
*/
- public boolean isIPv4CompatibleAddress ()
+ public boolean isIPv4CompatibleAddress()
{
- if (ipaddress [0] != 0x00 || ipaddress [1] != 0x00 ||
- ipaddress [2] != 0x00 || ipaddress [3] != 0x00 ||
- ipaddress [4] != 0x00 || ipaddress [5] != 0x00 ||
- ipaddress [6] != 0x00 || ipaddress [7] != 0x00 ||
- ipaddress [8] != 0x00 || ipaddress [9] != 0x00 ||
- ipaddress [10] != 0x00 || ipaddress [11] != 0x00)
+ if (ipaddress[0] != 0x00 || ipaddress[1] != 0x00 || ipaddress[2] != 0x00
+ || ipaddress[3] != 0x00 || ipaddress[4] != 0x00
+ || ipaddress[5] != 0x00 || ipaddress[6] != 0x00
+ || ipaddress[7] != 0x00 || ipaddress[8] != 0x00
+ || ipaddress[9] != 0x00 || ipaddress[10] != 0x00
+ || ipaddress[11] != 0x00)
return false;
return true;
Index: java/net/JarURLConnection.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/JarURLConnection.java,v
retrieving revision 1.18
diff -u -r1.18 JarURLConnection.java
--- java/net/JarURLConnection.java 6 Jan 2004 10:07:59 -0000 1.18
+++ java/net/JarURLConnection.java 8 Apr 2004 16:53:14 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,15 +35,15 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import java.io.IOException;
+import java.security.cert.Certificate;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
-import java.security.cert.Certificate;
+
/**
* This abstract class represents a common superclass for implementations
@@ -94,30 +94,29 @@
/**
* Creates a JarURLConnection from an URL object
*
- * @param URL url The URL object for this connection.
+ * @param url The URL object for this connection.
*
* @exception MalformedURLException If url is invalid
*
* @specnote This constructor is protected since JDK 1.4
*/
- protected JarURLConnection (URL url)
- throws MalformedURLException
+ protected JarURLConnection(URL url) throws MalformedURLException
{
- super (url);
+ super(url);
- if (!url.getProtocol().equals ("jar"))
- throw new MalformedURLException (url + ": Not jar protocol.");
+ if (! url.getProtocol().equals("jar"))
+ throw new MalformedURLException(url + ": Not jar protocol.");
String spec = url.getFile();
- int bang = spec.indexOf ("!/");
+ int bang = spec.indexOf("!/");
if (bang == -1)
- throw new MalformedURLException (url + ": No `!/' in spec.");
+ throw new MalformedURLException(url + ": No `!/' in spec.");
// 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 entry, if any.
- entryName = spec.length() == (bang + 2) ? null : spec.substring (bang + 2);
+ entryName = spec.length() == (bang + 2) ? null : spec.substring(bang + 2);
}
/**
@@ -126,7 +125,7 @@
*
* @return The remote URL
*/
- public URL getJarFileURL ()
+ public URL getJarFileURL()
{
return jarFileURL;
}
@@ -138,23 +137,23 @@
*
* @return The entry name.
*/
- public String getEntryName ()
+ public String getEntryName()
{
return entryName;
}
/**
- * Returns the entry in this jar file specified by the URL.
- *
+ * Returns the entry in this jar file specified by the URL.
+ *
* @return The jar entry
*
* @exception IOException If an error occurs
*/
- public JarEntry getJarEntry () throws IOException
+ public JarEntry getJarEntry() throws IOException
{
JarFile jarFile = getJarFile();
- return jarFile != null ? jarFile.getJarEntry (entryName) : null;
+ return jarFile != null ? jarFile.getJarEntry(entryName) : null;
}
/**
@@ -164,7 +163,7 @@
*
* @exception IOException If an error occurs
*/
- public abstract JarFile getJarFile () throws IOException;
+ public abstract JarFile getJarFile() throws IOException;
/**
* Returns an array of Certificate objects for the jar file entry specified
@@ -174,10 +173,10 @@
*
* @exception IOException If an error occurs
*/
- public Certificate[] getCertificates () throws IOException
+ public Certificate[] getCertificates() throws IOException
{
JarEntry entry = getJarEntry();
-
+
return entry != null ? entry.getCertificates() : null;
}
@@ -189,10 +188,10 @@
*
* @exception IOException If an error occurs
*/
- public Attributes getMainAttributes () throws IOException
+ public Attributes getMainAttributes() throws IOException
{
Manifest manifest = getManifest();
-
+
return manifest != null ? manifest.getMainAttributes() : null;
}
@@ -205,7 +204,7 @@
*
* @exception IOException If an error occurs
*/
- public Attributes getAttributes () throws IOException
+ public Attributes getAttributes() throws IOException
{
JarEntry entry = getJarEntry();
@@ -220,7 +219,7 @@
*
* @exception IOException If an error occurs
*/
- public Manifest getManifest () throws IOException
+ public Manifest getManifest() throws IOException
{
JarFile file = getJarFile();
Index: java/net/MimeTypeMapper.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/MimeTypeMapper.java,v
retrieving revision 1.4
diff -u -r1.4 MimeTypeMapper.java
--- java/net/MimeTypeMapper.java 22 Jan 2002 22:27:00 -0000 1.4
+++ java/net/MimeTypeMapper.java 8 Apr 2004 16:53:14 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,11 +35,11 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import java.util.Hashtable;
+
/**
* This non-public class is used to implement the FileNameMap interface
* which defines a mechanism for mapping filenames to MIME types.
@@ -50,7 +50,6 @@
*/
class MimeTypeMapper implements FileNameMap
{
-
/*************************************************************************/
/*
@@ -58,128 +57,129 @@
*/
/**
- * This array of strings is used to identify a MIME type based on a file
+ * This array of strings is used to identify a MIME type based on a file
* extension. This is list is based on the Apache mime.types file.
*/
-protected static final String[][] mime_strings = {
- { "application/mac-binhex40", "hqx" },
- { "application/mac-compactpro", "cpt" },
- { "application/msword", "doc" },
- { "application/octet-stream", "bin" },
- { "application/octet-stream", "dms" },
- { "application/octet-stream", "lha" },
- { "application/octet-stream", "lzh" },
- { "application/octet-stream", "exe" },
- { "application/octet-stream", "class" },
- { "application/oda", "oda" },
- { "application/pdf", "pdf" },
- { "application/postscript", "ai" },
- { "application/postscript", "eps" },
- { "application/postscript", "ps" },
- { "application/powerpoint", "ppt" },
- { "application/rtf", "rtf" },
- { "application/x-bcpio", "bcpio" },
- { "application/x-cdlink", "vcd" },
- { "application/x-compress", "Z" },
- { "application/x-cpio", "cpio" },
- { "application/x-csh", "csh" },
- { "application/x-director", "dcr" },
- { "application/x-director", "dir" },
- { "application/x-director", "dxr" },
- { "application/x-dvi", "dvi" },
- { "application/x-gtar", "gtar" },
- { "application/x-gzip", "gz" },
- { "application/x-hdf", "hdf" },
- { "application/x-httpd-cgi", "cgi" },
- { "application/x-koan", "skp" },
- { "application/x-koan", "skd" },
- { "application/x-koan", "skt" },
- { "application/x-koan", "skm" },
- { "application/x-latex", "latex" },
- { "application/x-mif", "mif" },
- { "application/x-netcdf", "nc" },
- { "application/x-netcdf", "cdf" },
- { "application/x-sh", "sh" },
- { "application/x-shar", "shar" },
- { "application/x-stuffit", "sit" },
- { "application/x-sv4cpio", "sv4cpio" },
- { "application/x-sv4crc", "sv4crc" },
- { "application/x-tar", "tar" },
- { "application/x-tcl", "tcl" },
- { "application/x-tex", "tex" },
- { "application/x-texinfo", "texinfo" },
- { "application/x-texinfo", "texi" },
- { "application/x-troff", "t" },
- { "application/x-troff", "tr" },
- { "application/x-troff", "roff" },
- { "application/x-troff-man", "man" },
- { "application/x-troff-me", "me" },
- { "application/x-troff-ms", "ms" },
- { "application/x-ustar", "ustar" },
- { "application/x-wais-source", "src" },
- { "application/zip", "zip" },
- { "audio/basic", "au" },
- { "audio/basic", "snd" },
- { "audio/mpeg", "mpga" },
- { "audio/mpeg", "mp2" },
- { "audio/mpeg", "mp3" },
- { "audio/x-aiff", "aif" },
- { "audio/x-aiff", "aiff" },
- { "audio/x-aiff", "aifc" },
- { "audio/x-pn-realaudio", "ram" },
- { "audio/x-pn-realaudio-plugin", "rpm" },
- { "audio/x-realaudio", "ra" },
- { "audio/x-wav", "wav" },
- { "chemical/x-pdb", "pdb" },
- { "chemical/x-pdb", "xyz" },
- { "image/gif", "gif" },
- { "image/ief", "ief" },
- { "image/jpeg", "jpeg" },
- { "image/jpeg", "jpg" },
- { "image/jpeg", "jpe" },
- { "image/png", "png" },
- { "image/tiff", "tiff" },
- { "image/tiff", "tif" },
- { "image/x-cmu-raster", "ras" },
- { "image/x-portable-anymap", "pnm" },
- { "image/x-portable-bitmap", "pbm" },
- { "image/x-portable-graymap", "pgm" },
- { "image/x-portable-pixmap", "ppm" },
- { "image/x-rgb", "rgb" },
- { "image/x-xbitmap", "xbm" },
- { "image/x-xpixmap", "xpm" },
- { "image/x-xwindowdump", "xwd" },
- { "text/html", "html" },
- { "text/html", "htm" },
- { "text/plain", "txt" },
- { "text/richtext", "rtx" },
- { "text/tab-separated-values", "tsv" },
- { "text/x-setext", "etx" },
- { "text/x-sgml", "sgml" },
- { "text/x-sgml", "sgm" },
- { "video/mpeg", "mpeg" },
- { "video/mpeg", "mpg" },
- { "video/mpeg", "mpe" },
- { "video/quicktime", "qt" },
- { "video/quicktime", "mov" },
- { "video/x-msvideo", "avi" },
- { "video/x-sgi-movie", "movie" },
- { "x-conference/x-cooltalk", "ice" },
- { "x-world/x-vrml", "wrl" },
- { "x-world/x-vrml", "vrml" }
- };
+ protected static final String[][] mime_strings =
+ {
+ { "application/mac-binhex40", "hqx" },
+ { "application/mac-compactpro", "cpt" },
+ { "application/msword", "doc" },
+ { "application/octet-stream", "bin" },
+ { "application/octet-stream", "dms" },
+ { "application/octet-stream", "lha" },
+ { "application/octet-stream", "lzh" },
+ { "application/octet-stream", "exe" },
+ { "application/octet-stream", "class" },
+ { "application/oda", "oda" },
+ { "application/pdf", "pdf" },
+ { "application/postscript", "ai" },
+ { "application/postscript", "eps" },
+ { "application/postscript", "ps" },
+ { "application/powerpoint", "ppt" },
+ { "application/rtf", "rtf" },
+ { "application/x-bcpio", "bcpio" },
+ { "application/x-cdlink", "vcd" },
+ { "application/x-compress", "Z" },
+ { "application/x-cpio", "cpio" },
+ { "application/x-csh", "csh" },
+ { "application/x-director", "dcr" },
+ { "application/x-director", "dir" },
+ { "application/x-director", "dxr" },
+ { "application/x-dvi", "dvi" },
+ { "application/x-gtar", "gtar" },
+ { "application/x-gzip", "gz" },
+ { "application/x-hdf", "hdf" },
+ { "application/x-httpd-cgi", "cgi" },
+ { "application/x-koan", "skp" },
+ { "application/x-koan", "skd" },
+ { "application/x-koan", "skt" },
+ { "application/x-koan", "skm" },
+ { "application/x-latex", "latex" },
+ { "application/x-mif", "mif" },
+ { "application/x-netcdf", "nc" },
+ { "application/x-netcdf", "cdf" },
+ { "application/x-sh", "sh" },
+ { "application/x-shar", "shar" },
+ { "application/x-stuffit", "sit" },
+ { "application/x-sv4cpio", "sv4cpio" },
+ { "application/x-sv4crc", "sv4crc" },
+ { "application/x-tar", "tar" },
+ { "application/x-tcl", "tcl" },
+ { "application/x-tex", "tex" },
+ { "application/x-texinfo", "texinfo" },
+ { "application/x-texinfo", "texi" },
+ { "application/x-troff", "t" },
+ { "application/x-troff", "tr" },
+ { "application/x-troff", "roff" },
+ { "application/x-troff-man", "man" },
+ { "application/x-troff-me", "me" },
+ { "application/x-troff-ms", "ms" },
+ { "application/x-ustar", "ustar" },
+ { "application/x-wais-source", "src" },
+ { "application/zip", "zip" },
+ { "audio/basic", "au" },
+ { "audio/basic", "snd" },
+ { "audio/mpeg", "mpga" },
+ { "audio/mpeg", "mp2" },
+ { "audio/mpeg", "mp3" },
+ { "audio/x-aiff", "aif" },
+ { "audio/x-aiff", "aiff" },
+ { "audio/x-aiff", "aifc" },
+ { "audio/x-pn-realaudio", "ram" },
+ { "audio/x-pn-realaudio-plugin", "rpm" },
+ { "audio/x-realaudio", "ra" },
+ { "audio/x-wav", "wav" },
+ { "chemical/x-pdb", "pdb" },
+ { "chemical/x-pdb", "xyz" },
+ { "image/gif", "gif" },
+ { "image/ief", "ief" },
+ { "image/jpeg", "jpeg" },
+ { "image/jpeg", "jpg" },
+ { "image/jpeg", "jpe" },
+ { "image/png", "png" },
+ { "image/tiff", "tiff" },
+ { "image/tiff", "tif" },
+ { "image/x-cmu-raster", "ras" },
+ { "image/x-portable-anymap", "pnm" },
+ { "image/x-portable-bitmap", "pbm" },
+ { "image/x-portable-graymap", "pgm" },
+ { "image/x-portable-pixmap", "ppm" },
+ { "image/x-rgb", "rgb" },
+ { "image/x-xbitmap", "xbm" },
+ { "image/x-xpixmap", "xpm" },
+ { "image/x-xwindowdump", "xwd" },
+ { "text/html", "html" },
+ { "text/html", "htm" },
+ { "text/plain", "txt" },
+ { "text/richtext", "rtx" },
+ { "text/tab-separated-values", "tsv" },
+ { "text/x-setext", "etx" },
+ { "text/x-sgml", "sgml" },
+ { "text/x-sgml", "sgm" },
+ { "video/mpeg", "mpeg" },
+ { "video/mpeg", "mpg" },
+ { "video/mpeg", "mpe" },
+ { "video/quicktime", "qt" },
+ { "video/quicktime", "mov" },
+ { "video/x-msvideo", "avi" },
+ { "video/x-sgi-movie", "movie" },
+ { "x-conference/x-cooltalk", "ice" },
+ { "x-world/x-vrml", "wrl" },
+ { "x-world/x-vrml", "vrml" }
+ };
/**
* The MIME types above are put into this Hashtable for faster lookup.
*/
-private static Hashtable mime_types = new Hashtable(150);
+ private static Hashtable mime_types = new Hashtable(150);
// Static initializer to load MIME types into Hashtable
-static
-{
- for (int i = 0; i < mime_strings.length; i++)
- mime_types.put(mime_strings[i][1], mime_strings[i][0]);
-}
+ static
+ {
+ for (int i = 0; i < mime_strings.length; i++)
+ mime_types.put(mime_strings[i][1], mime_strings[i][0]);
+ }
/*************************************************************************/
@@ -190,11 +190,10 @@
/**
* A do nothing constructor
*/
-public
-MimeTypeMapper()
-{
- ;
-}
+ public MimeTypeMapper()
+ {
+ ;
+ }
/*************************************************************************/
@@ -204,7 +203,7 @@
/**
* The method returns the MIME type of the filename passed as an argument.
- * The value returned is based on the extension of the filename. The
+ * The value returned is based on the extension of the filename. The
* default content type returned if this method cannot determine the
* actual content type is "application/octet-stream"
*
@@ -212,24 +211,21 @@
*
* @return The MIME type
*/
-public String
-getContentTypeFor(String filename)
-{
- int index = filename.lastIndexOf(".");
- if (index != -1)
- {
- if (index == filename.length())
- return("application/octet-stream");
- else
- filename = filename.substring(index + 1);
- }
-
- String type = (String)mime_types.get(filename);
- if (type == null)
- return("application/octet-stream");
- else
- return(type);
-}
-
+ public String getContentTypeFor(String filename)
+ {
+ int index = filename.lastIndexOf(".");
+ if (index != -1)
+ {
+ if (index == filename.length())
+ return ("application/octet-stream");
+ else
+ filename = filename.substring(index + 1);
+ }
+
+ String type = (String) mime_types.get(filename);
+ if (type == null)
+ return ("application/octet-stream");
+ else
+ return (type);
+ }
} // class MimeTypeMapper
-
Index: java/net/URI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URI.java,v
retrieving revision 1.5
diff -u -r1.5 URI.java
--- java/net/URI.java 20 Mar 2004 14:52:26 -0000 1.5
+++ java/net/URI.java 8 Apr 2004 16:53:14 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -44,14 +44,14 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
/**
* @author Ito Kazumitsu (address@hidden)
* @author Dalibor Topic (address@hidden)
* @author Michael Koch (address@hidden)
* @since 1.4
*/
-public final class URI
- implements Comparable, Serializable
+public final class URI implements Comparable, Serializable
{
static final long serialVersionUID = -6052424284110960213L;
@@ -70,11 +70,14 @@
private static final String RFC2396_DIGIT = "0123456789";
private static final String RFC2396_LOWALPHA = "abcdefghijklmnopqrstuvwxyz";
private static final String RFC2396_UPALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- private static final String RFC2396_ALPHA = RFC2396_LOWALPHA + RFC2396_UPALPHA;
+ private static final String RFC2396_ALPHA =
+ RFC2396_LOWALPHA + RFC2396_UPALPHA;
private static final String RFC2396_ALPHANUM = RFC2396_DIGIT + RFC2396_ALPHA;
private static final String RFC2396_MARK = "-_.!~*'()";
- private static final String RFC2396_UNRESERVED = RFC2396_ALPHANUM + RFC2396_MARK;
- private static final String RFC2396_REG_NAME = RFC2396_UNRESERVED + "$,;:@&=+";
+ private static final String RFC2396_UNRESERVED =
+ RFC2396_ALPHANUM + RFC2396_MARK;
+ private static final String RFC2396_REG_NAME =
+ RFC2396_UNRESERVED + "$,;:@&=+";
private static final String RFC2396_PCHAR = RFC2396_UNRESERVED + ":@&=+$,";
private static final String RFC2396_SEGMENT = RFC2396_PCHAR + ";";
private static final String RFC2396_PATH_SEGMENTS = RFC2396_SEGMENT + "/";
@@ -108,7 +111,6 @@
* Index of fragment component in parsed URI.
*/
private static final int FRAGMENT_GROUP = 10;
-
private String scheme;
private String rawSchemeSpecificPart;
private String schemeSpecificPart;
@@ -126,17 +128,17 @@
private String rawFragment;
private String fragment;
- private void readObject (ObjectInputStream is)
+ private void readObject(ObjectInputStream is)
throws ClassNotFoundException, IOException
{
}
- private void writeObject (ObjectOutputStream is)
- throws IOException
+ private void writeObject(ObjectOutputStream is) throws IOException
{
}
- private static String getURIGroup (Matcher match, int group) {
+ private static String getURIGroup(Matcher match, int group)
+ {
String matched = match.group(group);
return matched.length() == 0 ? null : matched;
}
@@ -148,23 +150,22 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- private void parseURI (String str)
- throws URISyntaxException
+ private void parseURI(String str) throws URISyntaxException
{
Pattern pattern = Pattern.compile(URI_REGEXP);
Matcher matcher = pattern.matcher(str);
if (matcher.matches())
{
scheme = getURIGroup(matcher, SCHEME_GROUP);
- rawSchemeSpecificPart = getURIGroup(matcher, SCHEME_SPEC_PART_GROUP);
+ rawSchemeSpecificPart = getURIGroup(matcher, SCHEME_SPEC_PART_GROUP);
rawAuthority = getURIGroup(matcher, AUTHORITY_GROUP);
rawPath = getURIGroup(matcher, PATH_GROUP);
rawQuery = getURIGroup(matcher, QUERY_GROUP);
rawFragment = getURIGroup(matcher, FRAGMENT_GROUP);
}
else
- throw new URISyntaxException(str,
- "doesn't match URI regular expression");
+ throw new URISyntaxException(str, "doesn't match URI regular expression");
+
// We must eagerly unquote the parts, because this is the only time
// we may throw an exception.
schemeSpecificPart = unquote(rawSchemeSpecificPart);
@@ -184,35 +185,39 @@
* @exception URISyntaxException If the given string contains invalid
* escape sequences.
*/
- private static String unquote (String str)
- throws URISyntaxException
+ private static String unquote(String str) throws URISyntaxException
{
if (str == null)
return null;
byte[] buf = new byte[str.length()];
int pos = 0;
- for (int i = 0; i < str.length(); i++) {
- char c = str.charAt(i);
- if (c > 127)
+ for (int i = 0; i < str.length(); i++)
+ {
+ char c = str.charAt(i);
+ if (c > 127)
throw new URISyntaxException(str, "Invalid character");
- if (c == '%') {
- if (i + 2 >= str.length())
- throw new URISyntaxException(str, "Invalid quoted character");
- String hex = "0123456789ABCDEF";
- int hi = hex.indexOf(str.charAt(++i));
- int lo = hex.indexOf(str.charAt(++i));
- if (lo < 0 || hi < 0)
- throw new URISyntaxException(str, "Invalid quoted character");
- buf[pos++] = (byte)(hi * 16 + lo);
- } else {
- buf[pos++] = (byte)c;
+ if (c == '%')
+ {
+ if (i + 2 >= str.length())
+ throw new URISyntaxException(str, "Invalid quoted character");
+ String hex = "0123456789ABCDEF";
+ int hi = hex.indexOf(str.charAt(++i));
+ int lo = hex.indexOf(str.charAt(++i));
+ if (lo < 0 || hi < 0)
+ throw new URISyntaxException(str, "Invalid quoted character");
+ buf[pos++] = (byte) (hi * 16 + lo);
+ }
+ else
+ buf[pos++] = (byte) c;
+ }
+ try
+ {
+ return new String(buf, 0, pos, "utf-8");
+ }
+ catch (java.io.UnsupportedEncodingException x2)
+ {
+ throw (Error) new InternalError().initCause(x2);
}
- }
- try {
- return new String(buf, 0, pos, "utf-8");
- } catch (java.io.UnsupportedEncodingException x2) {
- throw (Error)new InternalError().initCause(x2);
- }
}
/**
@@ -223,10 +228,11 @@
* UTF-8 character.
*
* @param str The string to quote
- *
+ *
* @return The quoted string.
*/
- private static String quote (String str) {
+ private static String quote(String str)
+ {
// FIXME: unimplemented.
return str;
}
@@ -239,10 +245,11 @@
* UTF-8 character.
*
* @param str The string to quote
- *
+ *
* @return The quoted string.
*/
- private static String quoteAuthority (String str) {
+ private static String quoteAuthority(String str)
+ {
// Technically, we should be using RFC2396_AUTHORITY, but
// it contains no additional characters.
return quote(str, RFC2396_REG_NAME);
@@ -257,37 +264,39 @@
*
* @param str The string to quote
* @param legalCharacters The set of legal characters
- *
+ *
* @return The quoted string.
*/
- private static String quote (String str, String legalCharacters)
+ private static String quote(String str, String legalCharacters)
{
StringBuffer sb = new StringBuffer(str.length());
- for (int i = 0; i < str.length(); i++) {
- char c = str.charAt(i);
- if (legalCharacters.indexOf(c) == -1) {
- String hex = "0123456789ABCDEF";
- if (c <= 127) {
- sb.append('%')
- .append(hex.charAt(c / 16))
- .append(hex.charAt(c % 16));
- } else {
- try {
- // this is far from optimal, but it works
- byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
- for (int j = 0; j < utf8.length; j++) {
- sb.append('%')
- .append(hex.charAt((utf8[j] & 0xff) / 16))
- .append(hex.charAt((utf8[j] & 0xff) % 16));
- }
- } catch (java.io.UnsupportedEncodingException x) {
- throw (Error)new InternalError().initCause(x);
+ for (int i = 0; i < str.length(); i++)
+ {
+ char c = str.charAt(i);
+ if (legalCharacters.indexOf(c) == -1)
+ {
+ String hex = "0123456789ABCDEF";
+ if (c <= 127)
+ sb.append('%').append(hex.charAt(c / 16)).append(hex.charAt(c % 16));
+ else
+ {
+ try
+ {
+ // this is far from optimal, but it works
+ byte[] utf8 = str.substring(i, i + 1).getBytes("utf-8");
+ for (int j = 0; j < utf8.length; j++)
+ sb.append('%').append(hex.charAt((utf8[j] & 0xff) / 16))
+ .append(hex.charAt((utf8[j] & 0xff) % 16));
+ }
+ catch (java.io.UnsupportedEncodingException x)
+ {
+ throw (Error) new InternalError().initCause(x);
+ }
+ }
}
- }
- } else {
- sb.append(c);
+ else
+ sb.append(c);
}
- }
return sb.toString();
}
@@ -299,10 +308,11 @@
* UTF-8 character.
*
* @param str The string to quote
- *
+ *
* @return The quoted string.
*/
- private static String quoteHost (String str) {
+ private static String quoteHost(String str)
+ {
// FIXME: unimplemented.
return str;
}
@@ -315,10 +325,11 @@
* UTF-8 character.
*
* @param str The string to quote
- *
+ *
* @return The quoted string.
*/
- private static String quotePath (String str) {
+ private static String quotePath(String str)
+ {
// Technically, we should be using RFC2396_PATH, but
// it contains no additional characters.
return quote(str, RFC2396_PATH_SEGMENTS);
@@ -332,10 +343,11 @@
* UTF-8 character.
*
* @param str The string to quote
- *
+ *
* @return The quoted string.
*/
- private static String quoteUserInfo (String str) {
+ private static String quoteUserInfo(String str)
+ {
// FIXME: unimplemented.
return str;
}
@@ -348,12 +360,11 @@
* @exception URISyntaxException If the given string violates RFC 2396
* @exception NullPointerException If str is null
*/
- public URI (String str)
- throws URISyntaxException
+ public URI(String str) throws URISyntaxException
{
parseURI(str);
}
-
+
/**
* Create an URI from the given components
*
@@ -367,19 +378,19 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- public URI (String scheme, String userInfo, String host, int port,
- String path, String query, String fragment)
+ public URI(String scheme, String userInfo, String host, int port,
+ String path, String query, String fragment)
throws URISyntaxException
{
- this((scheme == null ? "" : scheme + ":" )
- + (userInfo == null && host == null && port == -1 ? "" : "//")
- + (userInfo == null ? "" : quoteUserInfo(userInfo) + "@")
- + (host == null ? "" : quoteHost(host))
- + (port == -1 ? "" : ":" + String.valueOf(port))
- + (path == null ? "" : quotePath(path))
- + (query == null ? "" : "?" + quote(query))
- + (fragment == null ? "" : "#" + quote(fragment)));
-
+ this((scheme == null ? "" : scheme + ":")
+ + (userInfo == null && host == null && port == -1 ? "" : "//")
+ + (userInfo == null ? "" : quoteUserInfo(userInfo) + "@")
+ + (host == null ? "" : quoteHost(host))
+ + (port == -1 ? "" : ":" + String.valueOf(port))
+ + (path == null ? "" : quotePath(path))
+ + (query == null ? "" : "?" + quote(query))
+ + (fragment == null ? "" : "#" + quote(fragment)));
+
parseServerAuthority();
}
@@ -394,15 +405,14 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- public URI (String scheme, String authority, String path, String query,
- String fragment)
- throws URISyntaxException
+ public URI(String scheme, String authority, String path, String query,
+ String fragment) throws URISyntaxException
{
this((scheme == null ? "" : scheme + ":")
- + (authority == null ? "" : "//" + quoteAuthority(authority))
- + (path == null ? "" : quotePath(path))
- + (query == null ? "" : "?" + quote(query))
- + (fragment == null ? "" : "#" + quote(fragment)));
+ + (authority == null ? "" : "//" + quoteAuthority(authority))
+ + (path == null ? "" : quotePath(path))
+ + (query == null ? "" : "?" + quote(query))
+ + (fragment == null ? "" : "#" + quote(fragment)));
}
/**
@@ -415,7 +425,7 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- public URI (String scheme, String host, String path, String fragment)
+ public URI(String scheme, String host, String path, String fragment)
throws URISyntaxException
{
this(scheme, null, host, -1, path, null, fragment);
@@ -430,12 +440,12 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- public URI (String scheme, String ssp, String fragment)
+ public URI(String scheme, String ssp, String fragment)
throws URISyntaxException
{
this((scheme == null ? "" : scheme + ":")
- + (ssp == null ? "" : quote(ssp))
- + (fragment == null ? "" : "#" + quote(fragment)));
+ + (ssp == null ? "" : quote(ssp))
+ + (fragment == null ? "" : "#" + quote(fragment)));
}
/**
@@ -446,16 +456,16 @@
* @exception IllegalArgumentException If the given string violates RFC 2396
* @exception NullPointerException If str is null
*/
- public static URI create (String str)
+ public static URI create(String str)
{
try
{
return new URI(str);
}
- catch(URISyntaxException e)
+ catch (URISyntaxException e)
{
- throw (IllegalArgumentException)
- new IllegalArgumentException().initCause(e);
+ throw (IllegalArgumentException) new IllegalArgumentException()
+ .initCause(e);
}
}
@@ -465,8 +475,7 @@
*
* @exception URISyntaxException If the given string violates RFC 2396
*/
- public URI parseServerAuthority ()
- throws URISyntaxException
+ public URI parseServerAuthority() throws URISyntaxException
{
return null;
}
@@ -474,7 +483,7 @@
/**
* Returns a normalizes versions of the URI
*/
- public URI normalize ()
+ public URI normalize()
{
return null;
}
@@ -489,8 +498,8 @@
*
* @exception NullPointerException If uri is null
*/
- public URI resolve (URI uri)
- {
+ public URI resolve(URI uri)
+ {
if (uri.isAbsolute())
return uri;
if (uri.isOpaque())
@@ -505,35 +514,34 @@
try
{
- if (fragment != null &&
- path != null && path.equals("") &&
- scheme == null && authority == null && query == null)
+ if (fragment != null && path != null && path.equals("")
+ && scheme == null && authority == null && query == null)
return new URI(this.scheme, this.schemeSpecificPart, fragment);
- if (authority == null)
+ if (authority == null)
{
- authority = this.authority;
- if (path == null)
+ authority = this.authority;
+ if (path == null)
path = "";
- if (!(path.startsWith("/")))
+ if (! (path.startsWith("/")))
{
- StringBuffer basepath = new StringBuffer(this.path);
- int i = this.path.lastIndexOf('/');
+ StringBuffer basepath = new StringBuffer(this.path);
+ int i = this.path.lastIndexOf('/');
- if (i >= 0)
- basepath.delete(i+1, basepath.length());
+ if (i >= 0)
+ basepath.delete(i + 1, basepath.length());
- basepath.append(path);
- path = basepath.toString();
- // FIXME We must normalize the path here.
- // Normalization process omitted.
+ basepath.append(path);
+ path = basepath.toString();
+ // FIXME We must normalize the path here.
+ // Normalization process omitted.
}
}
- return new URI(this.scheme, authority, path, query, fragment);
+ return new URI(this.scheme, authority, path, query, fragment);
}
catch (URISyntaxException e)
{
- return null;
+ return null;
}
}
@@ -548,8 +556,7 @@
* violates RFC 2396
* @exception NullPointerException If uri is null
*/
- public URI resolve (String str)
- throws IllegalArgumentException
+ public URI resolve(String str) throws IllegalArgumentException
{
return resolve(create(str));
}
@@ -563,7 +570,7 @@
*
* @exception NullPointerException If uri is null
*/
- public URI relativize (URI uri)
+ public URI relativize(URI uri)
{
return null;
}
@@ -575,8 +582,7 @@
* not be found, or if some other error occurred while constructing the URL
* @exception IllegalArgumentException If the URI is not absolute
*/
- public URL toURL ()
- throws IllegalArgumentException, MalformedURLException
+ public URL toURL() throws IllegalArgumentException, MalformedURLException
{
if (isAbsolute())
return new URL(this.toString());
@@ -587,7 +593,7 @@
/**
* Returns the scheme of the URI
*/
- public String getScheme ()
+ public String getScheme()
{
return scheme;
}
@@ -595,7 +601,7 @@
/**
* Tells whether this URI is absolute or not
*/
- public boolean isAbsolute ()
+ public boolean isAbsolute()
{
return (scheme != null);
}
@@ -603,16 +609,16 @@
/**
* Tell whether this URI is opaque or not
*/
- public boolean isOpaque ()
+ public boolean isOpaque()
{
- return ((scheme != null) && !(schemeSpecificPart.startsWith("/")));
+ return ((scheme != null) && ! (schemeSpecificPart.startsWith("/")));
}
/**
* Returns the raw scheme specific part of this URI.
* The scheme-specific part is never undefined, though it may be empty
*/
- public String getRawSchemeSpecificPart ()
+ public String getRawSchemeSpecificPart()
{
return rawSchemeSpecificPart;
}
@@ -620,7 +626,7 @@
/**
* Returns the decoded scheme specific part of this URI.
*/
- public String getSchemeSpecificPart ()
+ public String getSchemeSpecificPart()
{
return schemeSpecificPart;
}
@@ -628,7 +634,7 @@
/**
* Returns the rae authority part of this URI
*/
- public String getRawAuthority ()
+ public String getRawAuthority()
{
return rawAuthority;
}
@@ -636,7 +642,7 @@
/**
* Returns the decoded authority part of this URI
*/
- public String getAuthority ()
+ public String getAuthority()
{
return authority;
}
@@ -644,7 +650,7 @@
/**
* Returns the raw user info part of this URI
*/
- public String getRawUserInfo ()
+ public String getRawUserInfo()
{
return rawUserInfo;
}
@@ -652,7 +658,7 @@
/**
* Returns the decoded user info part of this URI
*/
- public String getUserInfo ()
+ public String getUserInfo()
{
return userInfo;
}
@@ -660,7 +666,7 @@
/**
* Returns the hostname of the URI
*/
- public String getHost ()
+ public String getHost()
{
return host;
}
@@ -668,7 +674,7 @@
/**
* Returns the port number of the URI
*/
- public int getPort ()
+ public int getPort()
{
return port;
}
@@ -676,7 +682,7 @@
/**
* Returns the raw path part of this URI
*/
- public String getRawPath ()
+ public String getRawPath()
{
return rawPath;
}
@@ -684,7 +690,7 @@
/**
* Returns the path of the URI
*/
- public String getPath ()
+ public String getPath()
{
return path;
}
@@ -692,7 +698,7 @@
/**
* Returns the raw query part of this URI
*/
- public String getRawQuery ()
+ public String getRawQuery()
{
return rawQuery;
}
@@ -700,7 +706,7 @@
/**
* Returns the query of the URI
*/
- public String getQuery ()
+ public String getQuery()
{
return query;
}
@@ -708,7 +714,7 @@
/**
* Return the raw fragment part of this URI
*/
- public String getRawFragment ()
+ public String getRawFragment()
{
return rawFragment;
}
@@ -716,7 +722,7 @@
/**
* Returns the fragment of the URI
*/
- public String getFragment ()
+ public String getFragment()
{
return fragment;
}
@@ -734,7 +740,7 @@
/**
* Computes the hascode of the URI
*/
- public int hashCode ()
+ public int hashCode()
{
return 0;
}
@@ -746,8 +752,7 @@
*
* @exception ClassCastException If given object ist not an URI
*/
- public int compareTo (Object obj)
- throws ClassCastException
+ public int compareTo(Object obj) throws ClassCastException
{
return 0;
}
@@ -755,19 +760,19 @@
/**
* Returns the URI as string
*/
- public String toString ()
+ public String toString()
{
return (getScheme() == null ? "" : getScheme() + ":")
- + (getRawAuthority() == null ? "" : "//" + getRawAuthority())
- + (getRawPath() == null ? "" : getRawPath())
- + (getRawQuery() == null ? "" : "?" + getRawQuery())
- + (getRawFragment() == null ? "" : "#" + getRawFragment());
+ + (getRawAuthority() == null ? "" : "//" + getRawAuthority())
+ + (getRawPath() == null ? "" : getRawPath())
+ + (getRawQuery() == null ? "" : "?" + getRawQuery())
+ + (getRawFragment() == null ? "" : "#" + getRawFragment());
}
/**
* Returns the URI as US-ASCII string
*/
- public String toASCIIString ()
+ public String toASCIIString()
{
return "";
}
Index: java/net/URL.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URL.java,v
retrieving revision 1.25
diff -u -r1.25 URL.java
--- java/net/URL.java 31 Dec 2003 08:44:39 -0000 1.25
+++ java/net/URL.java 8 Apr 2004 16:53:14 -0000
@@ -7,7 +7,7 @@
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
-
+
GNU Classpath 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
@@ -35,18 +35,18 @@
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
-
package java.net;
import gnu.java.net.URLParseError;
-import java.io.InputStream;
import java.io.IOException;
-import java.io.Serializable;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.StringTokenizer;
+
/*
* Written using on-line Java Platform 1.2 API Specification, as well
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
@@ -56,7 +56,7 @@
/**
* This final class represents an Internet Uniform Resource Locator (URL).
* For details on the syntax of URL's and what they can be used for,
- * refer to RFC 1738, available from
* http://ds.internic.net/rfcs/rfc1738.txt
*
@@ -74,7 +74,7 @@ * This chaining is done via the system property java.protocol.handler.pkgs * If this property is set, it is assumed to be a "|" separated list of * package names in which to attempt locating protocol handlers. The - * protocol handler is searched for by appending the string + * protocol handler is searched for by appending the string * ".<protocol>.Handler" to each packed in the list until a hander is * found. If a protocol handler is not found in this list of packages, or if * the property does not exist, then the default protocol handler of @@ -87,7 +87,7 @@ *
* Here is an example of how URL searches for protocol handlers. Assume * the value of java.protocol.handler.pkgs is "com.foo|com.bar" and the - * URL is "news://comp.lang.java.programmer". URL would looking the + * URL is "news://comp.lang.java.programmer". URL would looking the * following places for protocol handlers: *
* com.foo.news.Handler @@ -122,7 +122,7 @@ { private static final String DEFAULT_SEARCH_PATH = "gnu.java.net.protocol|sun.net.www.protocol"; - + /** * The name of the protocol for this URL. * The protocol is always stored in lower case. @@ -144,7 +144,7 @@ * The port number of this protocol or -1 if the port number used is * the default for this protocol. */ - private int port = -1; // Initialize for constructor using context. + private int port = -1; // Initialize for constructor using context. /** * The "file" portion of the URL. It is defined aspath[?query]
. @@ -159,7 +159,7 @@ /** * This is the hashCode for this URL */ - private int hashCode = 0; + private int hashCode; /** * The protocol handler in use for this URL @@ -171,7 +171,6 @@ * where we keep track of it. */ private static URLStreamHandlerFactory factory; - private static final long serialVersionUID = -7627629688361524110L; /** @@ -187,18 +186,18 @@ static { - String s = System.getProperty ("gnu.java.net.nocache_protocol_handlers"); - + String s = System.getProperty("gnu.java.net.nocache_protocol_handlers"); + if (s == null) - cache_handlers = true; + cache_handlers = true; else - cache_handlers = false; + cache_handlers = false; } /** * Constructs a URL and loads a protocol handler for the values passed as * arguments. - * + * * @param protocol The protocol for this URL ("http", "ftp", etc) * @param host The hostname or IP address to connect to * @param port The port number to use, or -1 to use the protocol's @@ -231,11 +230,10 @@ this(protocol, host, -1, file, null); } - /** * This method initializes a new instance ofURL
with the * specified protocol, host, port, and file. Additionally, this method - * allows the caller to specify a protocol handler to use instead of + * allows the caller to specify a protocol handler to use instead of * the default. If this handler is specified, the caller must have * the "specifyStreamHandler" permission (seeNetPermission
) * or aSecurityException
will be thrown. @@ -254,9 +252,8 @@ * * @since 1.2 */ - public URL (String protocol, String host, int port, String file, - URLStreamHandler ph) - throws MalformedURLException + public URL(String protocol, String host, int port, String file, + URLStreamHandler ph) throws MalformedURLException { if (protocol == null) throw new MalformedURLException("null protocol"); @@ -266,16 +263,16 @@ { SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkPermission (new NetPermission ("specifyStreamHandler")); + s.checkPermission(new NetPermission("specifyStreamHandler")); - this.ph = ph; + this.ph = ph; } else this.ph = getURLStreamHandler(protocol); if (this.ph == null) - throw new MalformedURLException ( - "Protocol handler not found: " + protocol); + throw new MalformedURLException("Protocol handler not found: " + + protocol); this.host = host; this.port = port; @@ -292,7 +289,7 @@ this.file = file.substring(0, hashAt); this.ref = file.substring(hashAt + 1); } - hashCode = hashCode(); // Used for serialization. + hashCode = hashCode(); // Used for serialization. } /** @@ -325,7 +322,7 @@ * @param context The context on which to parse the specification * @param spec The string to parse an URL * - * @exception MalformedURLException If a protocol handler cannot be found + * @exception MalformedURLException If a protocol handler cannot be found * for the URL cannot be parsed */ public URL(URL context, String spec) throws MalformedURLException @@ -340,7 +337,7 @@ * not present the URL are inheritied from the context URL. This allows * relative URL's to be easily constructed. If the context argument is * null, then a complete URL must be specified in the URL string. - * If the protocol parsed out of the URL is different + * If the protocol parsed out of the URL is different * from the context URL's protocol, then then URL String is also * expected to be a complete URL. *@@ -372,7 +369,7 @@ * The relative URL need not specify all the components of a URL. * If the protocol, host name, or port number is missing, the value * is inherited from the context. A bare file component is appended - * to the context's file. The optional anchor is not inherited. + * to the context's file. The optional anchor is not inherited. */ // If this is an absolute URL, then ignore context completely. @@ -380,13 +377,13 @@ // right after the "://". The second colon is for an optional port value // and implies that the host from the context is used if available. int colon; - if ((colon = spec.indexOf("://", 1)) > 0 && - ! spec.regionMatches(colon, "://:", 0, 4)) + if ((colon = spec.indexOf("://", 1)) > 0 + && ! spec.regionMatches(colon, "://:", 0, 4)) context = null; int slash; - if ((colon = spec.indexOf(':')) > 0 && - (colon < (slash = spec.indexOf('/')) || slash < 0)) + if ((colon = spec.indexOf(':')) > 0 + && (colon < (slash = spec.indexOf('/')) || slash < 0)) { // Protocol specified in spec string. protocol = spec.substring(0, colon).toLowerCase(); @@ -412,26 +409,27 @@ file = context.file; if (file == null || file.length() == 0) file = "/"; - authority = context.authority; + authority = context.authority; } - else // Protocol NOT specified in spec. and no context available. - throw new - MalformedURLException("Absolute URL required with null context"); + else // Protocol NOT specified in spec. and no context available. + + + throw new MalformedURLException("Absolute URL required with null context"); if (ph != null) { - SecurityManager s = System.getSecurityManager (); + SecurityManager s = System.getSecurityManager(); if (s != null) - s.checkPermission (new NetPermission ("specifyStreamHandler")); + s.checkPermission(new NetPermission("specifyStreamHandler")); - this.ph = ph; + this.ph = ph; } else this.ph = getURLStreamHandler(protocol); if (this.ph == null) throw new MalformedURLException("Protocol handler not found: " - + protocol); + + protocol); // JDK 1.2 doc for parseURL specifically states that any '#' ref // is to be excluded by passing the 'limit' as the indexOf the '#' @@ -441,35 +439,35 @@ try { this.ph.parseURL(this, spec, colon + 1, - hashAt < 0 ? spec.length() : hashAt); + hashAt < 0 ? spec.length() : hashAt); } catch (URLParseError e) { throw new MalformedURLException(e.getMessage()); } - + if (hashAt >= 0) ref = spec.substring(hashAt + 1); - hashCode = hashCode(); // Used for serialization. + hashCode = hashCode(); // Used for serialization. } /** * Test another URL for equality with this one. This will be true only if - * the argument is non-null and all of the fields in the URL's match + * the argument is non-null and all of the fields in the URL's match * exactly (ie, protocol, host, port, file, and ref). Overrides * Object.equals(), implemented by calling the equals method of the handler. * - * @param url The URL to compare with + * @param obj The URL to compare with * * @return true if the URL is equal, false otherwise */ - public boolean equals (Object obj) + public boolean equals(Object obj) { if (! (obj instanceof URL)) return false; - return ph.equals (this, (URL) obj); + return ph.equals(this, (URL) obj); } /** @@ -482,7 +480,7 @@ * * @since 1.3 */ - public final Object getContent() throws IOException + public Object getContent() throws IOException { return openConnection().getContent(); } @@ -496,7 +494,7 @@ * * @exception IOException If an error occurs */ - public final Object getContent (Class[] classes) throws IOException + public Object getContent(Class[] classes) throws IOException { // FIXME: implement this return getContent(); @@ -519,7 +517,7 @@ * character. * * @return The path specified in this URL. - * + * * @since 1.3 */ public String getPath() @@ -532,7 +530,7 @@ * Returns the authority of the URL * * @return The authority specified in this URL. - * + * * @since 1.3 */ public String getAuthority() @@ -602,7 +600,7 @@ * * @return the user at a particular host or null when no user defined. */ - public String getUserInfo () + public String getUserInfo() { int at = (host == null) ? -1 : host.indexOf('@'); return at < 0 ? null : host.substring(0, at); @@ -614,7 +612,7 @@ * * @return the query part of the file, or null when there is no query part. */ - public String getQuery () + public String getQuery() { int quest = (file == null) ? -1 : file.indexOf('?'); return quest < 0 ? null : file.substring(quest + 1, file.length()); @@ -628,9 +626,9 @@ public int hashCode() { if (hashCode != 0) - return hashCode; // Use cached value if available. + return hashCode; // Use cached value if available. else - return ph.hashCode (this); + return ph.hashCode(this); } /** @@ -652,10 +650,10 @@ * from that connection * * @return An
InputStream
for this URL. - * + * * @exception IOException If an error occurs */ - public final InputStream openStream() throws IOException + public InputStream openStream() throws IOException { return openConnection().getInputStream(); } @@ -670,9 +668,9 @@ * * @return true if URL matches this URL's file, false otherwise */ - public boolean sameFile(URL other) + public boolean sameFile(URL url) { - return ph.sameFile(this, other); + return ph.sameFile(this, url); } /** @@ -688,7 +686,7 @@ * @param ref The anchor portion of this URL. */ protected void set(String protocol, String host, int port, String file, - String ref) + String ref) { // TBD: Theoretically, a poorly written StreamHandler could pass an // invalid protocol. It will cause the handler to be set to null @@ -701,7 +699,7 @@ this.host = host; this.file = file; this.ref = ref; - hashCode = hashCode(); // Used for serialization. + hashCode = hashCode(); // Used for serialization. } /** @@ -720,9 +718,8 @@ * * @since 1.3 */ - protected void set(String protocol, String host, int port, - String authority, String userInfo, - String path, String query, String ref) + protected void set(String protocol, String host, int port, String authority, + String userInfo, String path, String query, String ref) { // TBD: Theoretically, a poorly written StreamHandler could pass an // invalid protocol. It will cause the handler to be set to null @@ -740,7 +737,7 @@ else this.file = path + "?" + query; this.ref = ref; - hashCode = hashCode(); // Used for serialization. + hashCode = hashCode(); // Used for serialization. } /** @@ -754,8 +751,7 @@ * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation */ - public static synchronized void - setURLStreamHandlerFactory(URLStreamHandlerFactory fac) + public static synchronized void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) { if (factory != null) throw new Error("URLStreamHandlerFactory already set"); @@ -782,7 +778,7 @@ /** * Returns a String representing this URL. Identical to toExternalForm(). - * The value returned is created by the protocol handler's + * The value returned is created by the protocol handler's * toExternalForm method. Overrides Object.toString() * * @return A string for this URL @@ -801,23 +797,20 @@ * * @return A URLStreamHandler for this protocol, or null when not found. */ - private static synchronized URLStreamHandler - getURLStreamHandler (String protocol) + private static synchronized URLStreamHandler getURLStreamHandler(String protocol) { URLStreamHandler ph = null; // First, see if a protocol handler is in our cache. if (cache_handlers) { - if ((ph = (URLStreamHandler) ph_cache.get (protocol)) != null) - return ph; + if ((ph = (URLStreamHandler) ph_cache.get(protocol)) != null) + return ph; } // If a non-default factory has been set, use it to find the protocol. if (factory != null) - { - ph = factory.createURLStreamHandler (protocol); - } + ph = factory.createURLStreamHandler(protocol); // Non-default factory may have returned null or a factory wasn't set. // Use the default search algorithm to find a handler for this protocol. @@ -832,42 +825,41 @@ // Tack our default package on at the ends. if (ph_search_path != null) - ph_search_path += "|" + DEFAULT_SEARCH_PATH; + ph_search_path += "|" + DEFAULT_SEARCH_PATH; else - ph_search_path = DEFAULT_SEARCH_PATH; + ph_search_path = DEFAULT_SEARCH_PATH; // Finally loop through our search path looking for a match. - StringTokenizer pkgPrefix = new StringTokenizer (ph_search_path, "|"); - + StringTokenizer pkgPrefix = new StringTokenizer(ph_search_path, "|"); + do - { - String clsName = (pkgPrefix.nextToken() + "." - + protocol + ".Handler"); - - try - { - Object obj = Class.forName (clsName).newInstance(); - - if (!(obj instanceof URLStreamHandler)) - continue; - else - ph = (URLStreamHandler) obj; - } - catch (Exception e) - { - // Can't instantiate; handler still null, + { + String clsName = + (pkgPrefix.nextToken() + "." + protocol + ".Handler"); + + try + { + Object obj = Class.forName(clsName).newInstance(); + + if (! (obj instanceof URLStreamHandler)) + continue; + else + ph = (URLStreamHandler) obj; + } + catch (Exception e) + { + // Can't instantiate; handler still null, // go on to next element. - } - } - while ((! (ph instanceof URLStreamHandler)) - && pkgPrefix.hasMoreTokens()); + } + } + while ((! (ph instanceof URLStreamHandler)) + && pkgPrefix.hasMoreTokens()); } // Update the hashtable with the new protocol handler. - if (ph != null - && cache_handlers) + if (ph != null && cache_handlers) if (ph instanceof URLStreamHandler) - ph_cache.put (protocol, ph); + ph_cache.put(protocol, ph); else ph = null; Index: java/net/URLClassLoader.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v retrieving revision 1.19 diff -u -r1.19 URLClassLoader.java --- java/net/URLClassLoader.java 19 Sep 2003 06:19:42 -0000 1.19 +++ java/net/URLClassLoader.java 8 Apr 2004 16:53:15 -0000 @@ -7,7 +7,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath 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 @@ -35,7 +35,6 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package java.net; import java.io.ByteArrayOutputStream; @@ -43,23 +42,24 @@ import java.io.File; import java.io.FileInputStream; import java.io.FilePermission; -import java.io.InputStream; import java.io.IOException; -import java.security.AccessController; +import java.io.InputStream; import java.security.AccessControlContext; +import java.security.AccessController; import java.security.CodeSource; -import java.security.SecureClassLoader; -import java.security.PrivilegedAction; import java.security.PermissionCollection; +import java.security.PrivilegedAction; +import java.security.SecureClassLoader; import java.security.cert.Certificate; import java.util.Enumeration; -import java.util.Vector; import java.util.HashMap; +import java.util.Vector; import java.util.jar.Attributes; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.Manifest; + /** * A secure class loader that can load classes and resources from * multiple locations. Given an array ofURL
s this class @@ -117,7 +117,6 @@ * @author Mark Wielaard (address@hidden) * @author Wu Gansha (address@hidden) */ - public class URLClassLoader extends SecureClassLoader { // Class Variables @@ -129,7 +128,7 @@ * XXX - Keeps these loaders forever which prevents garbage collection. */ private static HashMap urlloaders = new HashMap(); - + /** * A cache to store mappings between handler factory and its * private protocol handler cache (also a HashMap), so we can avoid @@ -143,12 +142,12 @@ private final Vector urls = new Vector(); /** - * Store pre-parsed information for each url into this vector - * each element is a URL loader, corresponding to the URL of + * Store pre-parsed information for each url into this vector + * each element is a URL loader, corresponding to the URL of * the same index in "urls" */ private final Vector urlinfos = new Vector(); - + /** Factory used to get the protocol handlers of the URLs */ private final URLStreamHandlerFactory factory; @@ -160,12 +159,12 @@ private final AccessControlContext securityContext; // Helper classes - - /** + + /** * AURLLoader
contains all logic to load resources from a * given baseURL
. */ - static abstract class URLLoader + abstract static class URLLoader { /** * Our classloader to get info from if needed. @@ -211,14 +210,14 @@ } } - /** + /** * AResource
represents a resource in some *URLLoader
. It also contains all information (e.g., *URL
,CodeSource
,Manifest
and *InputStream
) that is necessary for loading resources * and creating classes from aURL
. */ - static abstract class Resource + abstract static class Resource { final URLLoader loader; final String name; @@ -273,10 +272,10 @@ * AJarURLLoader
is a type ofURLLoader
* only loading from jar url. */ - final static class JarURLLoader extends URLLoader + static final class JarURLLoader extends URLLoader { final JarFile jarfile; // The jar file for this url - final URL baseJarURL; // Base jar: url for all resources loaded from jar + final URL baseJarURL; // Base jar: url for all resources loaded from jar public JarURLLoader(URLClassLoader classloader, URL baseURL) { @@ -293,13 +292,17 @@ URL baseJarURL = null; JarFile jarfile = null; try - { - baseJarURL - = new URL(null, jarURL, classloader.getURLStreamHandler("jar")); - jarfile - = ((JarURLConnection) baseJarURL.openConnection()).getJarFile(); - } - catch (IOException ioe) { /* ignored */ } + { + baseJarURL = + new URL(null, jarURL, classloader.getURLStreamHandler("jar")); + + jarfile = + ((JarURLConnection) baseJarURL.openConnection()).getJarFile(); + } + catch (IOException ioe) + { + /* ignored */ + } this.baseJarURL = baseJarURL; this.jarfile = jarfile; @@ -312,10 +315,10 @@ return null; if (name.startsWith("/")) - name = name.substring(1); + name = name.substring(1); JarEntry je = jarfile.getJarEntry(name); - if(je != null) + if (je != null) return new JarURLResource(this, name, je); else return null; @@ -324,17 +327,17 @@ Manifest getManifest() { try - { + { return (jarfile == null) ? null : jarfile.getManifest(); - } + } catch (IOException ioe) - { + { return null; - } + } } } - final static class JarURLResource extends Resource + static final class JarURLResource extends Resource { private final JarEntry entry; @@ -346,12 +349,12 @@ InputStream getInputStream() throws IOException { - return ((JarURLLoader)loader).jarfile.getInputStream(entry); + return ((JarURLLoader) loader).jarfile.getInputStream(entry); } int getLength() { - return (int)entry.getSize(); + return (int) entry.getSize(); } Certificate[] getCertificates() @@ -362,25 +365,25 @@ URL getURL() { try - { - return new URL(((JarURLLoader)loader).baseJarURL, name, - loader.classloader.getURLStreamHandler("jar")); - } - catch(MalformedURLException e) - { + { + return new URL(((JarURLLoader) loader).baseJarURL, name, + loader.classloader.getURLStreamHandler("jar")); + } + catch (MalformedURLException e) + { InternalError ie = new InternalError(); ie.initCause(e); throw ie; - } + } } } /** * Loader for remote directories. */ - final static class RemoteURLLoader extends URLLoader + static final class RemoteURLLoader extends URLLoader { - final private String protocol; + private final String protocol; RemoteURLLoader(URLClassLoader classloader, URL url) { @@ -395,9 +398,9 @@ Resource getResource(String name) { try - { - URL url = new URL(baseURL, name, - classloader.getURLStreamHandler(protocol)); + { + URL url = + new URL(baseURL, name, classloader.getURLStreamHandler(protocol)); URLConnection connection = url.openConnection(); // Open the connection and check the stream @@ -408,9 +411,9 @@ // 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) + int response = + ((HttpURLConnection) connection).getResponseCode(); + if (response / 100 != 2) return null; } @@ -418,25 +421,25 @@ 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 + static final class RemoteResource extends Resource { - final private URL url; - final private InputStream stream; - final private int length; + private final URL url; + private final InputStream stream; + private final int length; RemoteResource(RemoteURLLoader loader, String name, URL url, - InputStream stream, int length) + InputStream stream, int length) { super(loader, name); this.url = url; @@ -464,9 +467,9 @@ * AFileURLLoader
is a type ofURLLoader
* only loading from file url. */ - final static class FileURLLoader extends URLLoader + static final class FileURLLoader extends URLLoader { - File dir; //the file for this file url + File dir; //the file for this file url FileURLLoader(URLClassLoader classloader, URL url) { @@ -478,13 +481,13 @@ Resource getResource(String name) { File file = new File(dir, name); - if (file.exists() && !file.isDirectory()) + if (file.exists() && ! file.isDirectory()) return new FileResource(this, name, file); return null; } } - final static class FileResource extends Resource + static final class FileResource extends Resource { final File file; @@ -498,28 +501,28 @@ { return new FileInputStream(file); } - + public int getLength() { - return (int)file.length(); + return (int) file.length(); } public URL getURL() { try - { + { return new URL(loader.baseURL, name, - loader.classloader.getURLStreamHandler("file")); - } - catch(MalformedURLException e) - { + loader.classloader.getURLStreamHandler("file")); + } + catch (MalformedURLException e) + { InternalError ie = new InternalError(); ie.initCause(e); throw ie; - } + } } } - + // Constructors /** @@ -573,7 +576,7 @@ * load classes and resources (after using the supplied parent ClassLoader). * @exception SecurityException if the SecurityManager disallows the * creation of a ClassLoader. - * @exception SecurityException + * @exception SecurityException * @param urls Locations that should be searched by this ClassLoader when * resolving Classes or Resources. * @param parent The parent class loader used before trying this class @@ -603,7 +606,7 @@ * @param securityContext the security context of the unprivileged code. */ private URLClassLoader(ClassLoader parent, - AccessControlContext securityContext) + AccessControlContext securityContext) { super(parent); this.factory = null; @@ -621,7 +624,7 @@ * protocol handlers of the supplied URLs. * @exception SecurityException if the SecurityManager disallows the * creation of a ClassLoader. - * @exception SecurityException + * @exception SecurityException * @param urls Locations that should be searched by this ClassLoader when * resolving Classes or Resources. * @param parent The parent class loader used before trying this class @@ -629,9 +632,8 @@ * @param factory Used to get the protocol handler for the URLs. * @see SecureClassLoader */ - public URLClassLoader(URL[] urls, - ClassLoader parent, - URLStreamHandlerFactory factory) + public URLClassLoader(URL[] urls, ClassLoader parent, + URLStreamHandlerFactory factory) throws SecurityException { super(parent); @@ -642,7 +644,7 @@ // If this factory is still not in factoryCache, add it, // since we only support three protocols so far, 5 is enough // for cache initial size - synchronized(factoryCache) + synchronized (factoryCache) { if (factory != null && factoryCache.get(factory) == null) factoryCache.put(factory, new HashMap(5)); @@ -662,17 +664,18 @@ private void addURLImpl(URL newUrl) { - synchronized(urlloaders) + synchronized (urlloaders) { if (newUrl == null) return; // Silently ignore... - + // Check global cache to see if there're already url loader // for this url. - URLLoader loader = (URLLoader)urlloaders.get(newUrl); + URLLoader loader = (URLLoader) urlloaders.get(newUrl); if (loader == null) { String file = newUrl.getFile(); + // Check that it is not a directory if (! (file.endsWith("/") || file.endsWith(File.separator))) loader = new JarURLLoader(this, newUrl); @@ -697,12 +700,10 @@ private void addURLs(URL[] newUrls) { for (int i = 0; i < newUrls.length; i++) - { addURLImpl(newUrls[i]); - } } - /** + /** * Defines a Package based on the given name and the supplied manifest * information. The manifest indicates the tile, version and * vendor information of the specification and implementation and wheter the @@ -717,22 +718,16 @@ * @param url the code source url to seal the package * @return the defined Package */ - protected Package definePackage(String name, Manifest manifest, URL url) + protected Package definePackage(String name, Manifest manifest, URL url) throws IllegalArgumentException { Attributes attr = manifest.getMainAttributes(); - String specTitle = - attr.getValue(Attributes.Name.SPECIFICATION_TITLE); - String specVersion = - attr.getValue(Attributes.Name.SPECIFICATION_VERSION); - String specVendor = - attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); - String implTitle = - attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE); - String implVersion = - attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); - String implVendor = - attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); + String specTitle = attr.getValue(Attributes.Name.SPECIFICATION_TITLE); + String specVersion = attr.getValue(Attributes.Name.SPECIFICATION_VERSION); + String specVendor = attr.getValue(Attributes.Name.SPECIFICATION_VENDOR); + String implTitle = attr.getValue(Attributes.Name.IMPLEMENTATION_TITLE); + String implVersion = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION); + String implVendor = attr.getValue(Attributes.Name.IMPLEMENTATION_VENDOR); // Look if the Manifest indicates that this package is sealed // XXX - most likely not completely correct! @@ -741,13 +736,11 @@ // But how do we get that jar manifest here? String sealed = attr.getValue(Attributes.Name.SEALED); if ("false".equals(sealed)) - { // make sure that the URL is null so the package is not sealed url = null; - } - return definePackage(name, specTitle, specVersion, specVendor, - implTitle, implVersion, implVendor, url); + return definePackage(name, specTitle, specVersion, specVendor, implTitle, + implVersion, implVendor, url); } /** @@ -772,87 +765,81 @@ // construct the class (and watch out for those nasty IOExceptions) try { - byte [] data; + byte[] data; InputStream in = resource.getInputStream(); try { int length = resource.getLength(); if (length != -1) - { + { // We know the length of the data. // Just try to read it in all at once data = new byte[length]; int pos = 0; - while(length - pos > 0) - { + while (length - pos > 0) + { int len = in.read(data, pos, length - pos); if (len == -1) - throw new EOFException("Not enough data reading from: " - + in); + throw new EOFException("Not enough data reading from: " + + in); pos += len; - } - } + } + } else - { + { // We don't know the data length. // Have to read it in chunks. ByteArrayOutputStream out = new ByteArrayOutputStream(4096); - byte b[] = new byte[4096]; + byte[] b = new byte[4096]; int l = 0; while (l != -1) - { + { l = in.read(b); if (l != -1) - out.write(b, 0, l); - } + out.write(b, 0, l); + } data = out.toByteArray(); - } + } } - finally - { + finally + { in.close(); - } + } final byte[] classData = data; // Now get the CodeSource final CodeSource source = resource.getCodeSource(); - + // Find out package name String packageName = null; int lastDot = className.lastIndexOf('.'); if (lastDot != -1) packageName = className.substring(0, lastDot); - + if (packageName != null && getPackage(packageName) == null) { // define the package Manifest manifest = resource.loader.getManifest(); if (manifest == null) - definePackage(packageName, - null, null, null, null, null, null, null); + definePackage(packageName, null, null, null, null, null, null, + null); else definePackage(packageName, manifest, resource.loader.baseURL); } - + // And finally construct the class! SecurityManager sm = System.getSecurityManager(); if (sm != null && securityContext != null) - { - return (Class)AccessController.doPrivileged - (new PrivilegedAction() + return (Class) AccessController.doPrivileged(new PrivilegedAction() + { + public Object run() { - public Object run() - { - return defineClass(className, classData, - 0, classData.length, - source); - } - }, securityContext); - } + return defineClass(className, classData, 0, + classData.length, source); + } + }, securityContext); else - return defineClass(className, classData, - 0, classData.length, - source); + return defineClass(className, classData, 0, classData.length, source); } catch (IOException ioe) { @@ -872,10 +859,10 @@ int max = urls.size(); for (int i = 0; i < max; i++) { - URLLoader loader = (URLLoader)urlinfos.elementAt(i); + URLLoader loader = (URLLoader) urlinfos.elementAt(i); if (loader == null) continue; - + Resource resource = loader.getResource(resourceName); if (resource != null) return resource; @@ -894,7 +881,7 @@ Resource resource = findURLResource(resourceName); if (resource != null) return resource.getURL(); - + // Resource not found return null; } @@ -915,9 +902,9 @@ synchronized (factoryCache) { // Check if there're handler for the same protocol in cache. - HashMap cache = (HashMap)factoryCache.get(factory); - handler = (URLStreamHandler)cache.get(protocol); - if(handler == null) + HashMap cache = (HashMap) factoryCache.get(factory); + handler = (URLStreamHandler) cache.get(protocol); + if (handler == null) { // Add it to cache. handler = factory.createURLStreamHandler(protocol); @@ -936,13 +923,14 @@ * @return a (possible empty) enumeration of URLs where the resource can be * found */ - public Enumeration findResources(String resourceName) throws IOException + public Enumeration findResources(String resourceName) + throws IOException { Vector resources = new Vector(); int max = urls.size(); for (int i = 0; i < max; i++) { - URLLoader loader = (URLLoader)urlinfos.elementAt(i); + URLLoader loader = (URLLoader) urlinfos.elementAt(i); Resource resource = loader.getResource(resourceName); if (resource != null) resources.add(resource.getURL()); @@ -974,29 +962,25 @@ { // XXX - This implementation does exactly as the Javadoc describes. // But maybe we should/could use URLConnection.getPermissions()? - // First get the permissions that would normally be granted PermissionCollection permissions = super.getPermissions(source); - + // Now add any extra permissions depending on the URL location. URL url = source.getLocation(); String protocol = url.getProtocol(); if (protocol.equals("file")) { String file = url.getFile(); + // If the file end in / it must be an directory. if (file.endsWith("/") || file.endsWith(File.separator)) - { - // Grant permission to read everything in that directory and - // all subdirectories. - permissions.add(new FilePermission(file + "-", "read")); - } + // Grant permission to read everything in that directory and + // all subdirectories. + permissions.add(new FilePermission(file + "-", "read")); else - { - // It is a 'normal' file. - // Grant permission to access that file. - permissions.add(new FilePermission(file, "read")); - } + // It is a 'normal' file. + // Grant permission to access that file. + permissions.add(new FilePermission(file, "read")); } else { @@ -1008,7 +992,7 @@ return permissions; } - + /** * Returns all the locations that this class loader currently uses the * resolve classes and resource. This includes both the initially supplied @@ -1031,7 +1015,7 @@ * @exception SecurityException when the calling code does not have * permission to access the givenURL
s */ - public static URLClassLoader newInstance(URL urls[]) + public static URLClassLoader newInstance(URL[] urls) throws SecurityException { return newInstance(urls, null); @@ -1049,8 +1033,7 @@ * @exception SecurityException when the calling code does not have * permission to access the givenURL
s */ - public static URLClassLoader newInstance(URL urls[], - final ClassLoader parent) + public static URLClassLoader newInstance(URL[] urls, final ClassLoader parent) throws SecurityException { SecurityManager sm = System.getSecurityManager(); @@ -1059,21 +1042,21 @@ else { final Object securityContext = sm.getSecurityContext(); + // XXX - What to do with anything else then an AccessControlContext? - if (!(securityContext instanceof AccessControlContext)) - throw new SecurityException - ("securityContext must be AccessControlContext: " - + securityContext); - + if (! (securityContext instanceof AccessControlContext)) + throw new SecurityException("securityContext must be AccessControlContext: " + + securityContext); + URLClassLoader loader = - (URLClassLoader)AccessController.doPrivileged(new PrivilegedAction() - { - public Object run() + (URLClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - return new URLClassLoader - (parent, (AccessControlContext)securityContext); - } - }); + public Object run() + { + return new URLClassLoader(parent, + (AccessControlContext) securityContext); + } + }); loader.addURLs(urls); return loader; } Index: java/net/URLConnection.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/net/URLConnection.java,v retrieving revision 1.23 diff -u -r1.23 URLConnection.java --- java/net/URLConnection.java 27 Feb 2004 11:02:55 -0000 1.23 +++ java/net/URLConnection.java 8 Apr 2004 16:53:15 -0000 @@ -7,7 +7,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath 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 @@ -35,11 +35,10 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package java.net; -import java.io.InputStream; import java.io.IOException; +import java.io.InputStream; import java.io.OutputStream; import java.security.AllPermission; import java.security.Permission; @@ -51,13 +50,13 @@ import java.util.Locale; import java.util.Map; + /** * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * Status: One guessContentTypeFrom... methods not implemented. * getContent method assumes content type from response; see comment there. */ - /** * This class models a connection that retrieves the information pointed * to by a URL object. This is typically a connection to a remote node @@ -97,18 +96,18 @@ * instance and store it here. */ private static FileNameMap fileNameMap; - + /** * This is the ContentHandlerFactory set by the caller, if any */ private static ContentHandlerFactory factory; - + /** * This is the default value that will be used to determine whether or * not user interaction should be allowed. */ - private static boolean defaultAllowUserInteraction = false; - + private static boolean defaultAllowUserInteraction; + /** * This is the default flag indicating whether or not to use caches to * store the data returned from a server @@ -125,18 +124,18 @@ * Indicates whether or not a connection has been established to the * destination specified in the URL */ - protected boolean connected = false; - + protected boolean connected; + /** * Indicates whether or not input can be read from this URL */ protected boolean doInput = true; - + /** * Indicates whether or not output can be sent to this URL */ - protected boolean doOutput = false; - + protected boolean doOutput; + /** * If this flag is set, the protocol is allowed to cache data whenever * it can (caching is not guaranteed). If it is not set, the protocol @@ -156,15 +155,16 @@ * modified more recently than the date set in this variable. That date * should be specified as the number of seconds since 1/1/1970 GMT. */ - protected long ifModifiedSince = 0L; + protected long ifModifiedSince; /** * This is the URL associated with this connection */ protected URL url; - - private static SimpleDateFormat dateFormat1, dateFormat2, dateFormat3; - private static boolean dateformats_initialized = false; + private static SimpleDateFormat dateFormat1; + private static SimpleDateFormat dateFormat2; + private static SimpleDateFormat dateFormat3; + private static boolean dateformats_initialized; /** * Creates a URL connection to a given URL. A real connection is not made. @@ -185,6 +185,8 @@ /** * Establishes the actual connection to the URL associated with this * connection object + * + * @exception IOException if an error occurs */ public abstract void connect() throws IOException; @@ -227,7 +229,7 @@ /** * Returns the value of the content-encoding field or null if it is not * known or not present. - * + * * @return The content-encoding field */ public String getContentEncoding() @@ -292,7 +294,7 @@ * Returns a String representing the value of the header field having * the named key. Returns null if the header field does not exist. * - * @param The key of the header field + * @param name The key of the header field * * @return The value of the header field as a String */ @@ -304,7 +306,9 @@ /** * Returns a map of all sent header fields - * + * + * @return all header fields + * * @since 1.4 */ public Map getHeaderFields() @@ -327,18 +331,18 @@ */ public int getHeaderFieldInt(String name, int defaultValue) { - String value = getHeaderField (name); - + String value = getHeaderField(name); + if (value == null) return defaultValue; try { - return Integer.parseInt (value); + return Integer.parseInt(value); } - catch (NumberFormatException e) - { - return defaultValue; + catch (NumberFormatException e) + { + return defaultValue; } } @@ -354,25 +358,25 @@ * @return Returns the date value of the header filed or the default value * if the field is missing or malformed */ - public long getHeaderFieldDate (String name, long defaultValue) + public long getHeaderFieldDate(String name, long defaultValue) { if (! dateformats_initialized) - initializeDateFormats (); - + initializeDateFormats(); + long result = defaultValue; - String str = getHeaderField (name); - + String str = getHeaderField(name); + if (str != null) { Date date; - if ((date = dateFormat1.parse (str, new ParsePosition (0))) != null) - result = date.getTime (); - else if ((date = dateFormat2.parse (str, new ParsePosition (0))) != null) - result = date.getTime (); - else if ((date = dateFormat3.parse (str, new ParsePosition (0))) != null) - result = date.getTime (); + if ((date = dateFormat1.parse(str, new ParsePosition(0))) != null) + result = date.getTime(); + else if ((date = dateFormat2.parse(str, new ParsePosition(0))) != null) + result = date.getTime(); + else if ((date = dateFormat3.parse(str, new ParsePosition(0))) != null) + result = date.getTime(); } - + return result; } @@ -382,12 +386,12 @@ * getHeaderField(int) method allows access to the corresponding value for * this tag. * - * @param index The index into the header field list to retrieve the key for. + * @param index The index into the header field list to retrieve the key for. * * @return The header field key or null if index is past the end * of the headers. */ - public String getHeaderFieldKey (int index) + public String getHeaderFieldKey(int index) { // Subclasses for specific protocols override this. return null; @@ -419,7 +423,7 @@ // First try the factory ContentHandler ch = null; - + if (factory != null) ch = factory.createContentHandler(type); @@ -429,16 +433,16 @@ // Then try our default class try { - Class cls = Class.forName("gnu.java.net.content." + - type.replace('/', '.')); - - Object obj = cls.newInstance(); - + Class cls = + Class.forName("gnu.java.net.content." + type.replace('/', '.')); + + Object obj = cls.newInstance(); + if (! (obj instanceof ContentHandler)) - throw new UnknownServiceException(type); + throw new UnknownServiceException(type); - ch = (ContentHandler) obj; - return ch.getContent(this); + ch = (ContentHandler) obj; + return ch.getContent(this); } catch (ClassNotFoundException e) { @@ -456,6 +460,8 @@ /** * Retrieves the content of this URLConnection * + * @param classes The allowed classes for the content + * * @exception IOException If an error occurs * @exception UnknownServiceException If the protocol does not support the * content type @@ -463,7 +469,7 @@ public Object getContent(Class[] classes) throws IOException { // FIXME: implement this - return getContent (); + return getContent(); } /** @@ -500,8 +506,8 @@ public InputStream getInputStream() throws IOException { // Subclasses for specific protocols override this. - throw new UnknownServiceException("Protocol " + url.getProtocol() + - " does not support input."); + throw new UnknownServiceException("Protocol " + url.getProtocol() + + " does not support input."); } /** @@ -516,14 +522,14 @@ public OutputStream getOutputStream() throws IOException { // Subclasses for specific protocols override this. - throw new UnknownServiceException("Protocol " + url.getProtocol() + - " does not support output."); + throw new UnknownServiceException("Protocol " + url.getProtocol() + + " does not support output."); } /** * The methods prints the value of this object as a String by calling the * toString() method of its associated URL. Overrides Object.toString() - * + * * @return A String representation of this object */ public String toString() @@ -535,7 +541,7 @@ * Returns the value of a flag indicating whether or not input is going * to be done for this connection. This default to true unless the * doOutput flag is set to false, in which case this defaults to false. - * + * * @param inputtrue
if input is to be done, *false
otherwise * @@ -544,7 +550,7 @@ public void setDoInput(boolean input) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); doInput = input; } @@ -573,7 +579,7 @@ public void setDoOutput(boolean output) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); doOutput = output; } @@ -648,7 +654,7 @@ public void setUseCaches(boolean usecaches) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); useCaches = usecaches; } @@ -679,7 +685,7 @@ public void setIfModifiedSince(long ifmodifiedsince) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); ifModifiedSince = ifmodifiedsince; } @@ -715,9 +721,9 @@ * * @param use true to use caches if possible by default, false otherwise */ - public void setDefaultUseCaches(boolean defaultusecaches) + public void setDefaultUseCaches(boolean use) { - defaultUseCaches = defaultusecaches; + defaultUseCaches = use; } /** @@ -725,23 +731,23 @@ * * @param key The name of the property * @param value The value of the property - * + * * @exception IllegalStateException If already connected * @exception NullPointerException If key is null * * @see URLConnection#getRequestProperty(String key) * @see URLConnection#addRequestProperty(String key, String value) - * + * * @since 1.4 */ public void setRequestProperty(String key, String value) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); if (key == null) - throw new NullPointerException ("key is null"); - + throw new NullPointerException("key is null"); + // Do nothing unless overridden by subclasses that support setting // header fields in the request. } @@ -755,20 +761,20 @@ * * @exception IllegalStateException If already connected * @exception NullPointerException If key is null - * + * * @see URLConnection#getRequestProperty(String key) * @see URLConnection#setRequestProperty(String key, String value) - * + * * @since 1.4 */ public void addRequestProperty(String key, String value) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); if (key == null) - throw new NullPointerException ("key is null"); - + throw new NullPointerException("key is null"); + // Do nothing unless overridden by subclasses that support adding // header fields in the request. } @@ -788,7 +794,7 @@ public String getRequestProperty(String key) { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); // Overridden by subclasses that support reading header fields from the // request. @@ -807,7 +813,7 @@ public Map getRequestProperties() { if (connected) - throw new IllegalStateException ("Already connected"); + throw new IllegalStateException("Already connected"); // Overridden by subclasses that support reading header fields from the // request. @@ -827,7 +833,7 @@ * * @see URLConnection#setRequestProperty(String key, String value) */ - public static void setDefaultRequestProperty (String key, String value) + public static void setDefaultRequestProperty(String key, String value) { // This method does nothing since JDK 1.3. } @@ -840,7 +846,7 @@ * @param key The request property to return the default value of * * @return The value of the default property or null if not available - * + * * @deprecated 1.3 The method getRequestProperty should be used instead. * This method does nothing now. * @@ -864,8 +870,7 @@ * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation */ - public static synchronized void setContentHandlerFactory - (ContentHandlerFactory fac) + public static synchronized void setContentHandlerFactory(ContentHandlerFactory factory) { if (factory != null) throw new Error("ContentHandlerFactory already set"); @@ -876,7 +881,7 @@ if (s != null) s.checkSetFactory(); - factory = fac; + URLConnection.factory = factory; } /** @@ -900,7 +905,7 @@ * Returns the MIME type of a stream based on the first few characters * at the beginning of the stream. This routine can be used to determine * the MIME type if a server is believed to be returning an incorrect - * MIME type. This method returns "application/octet-stream" if it + * MIME type. This method returns "application/octet-stream" if it * cannot determine the MIME type. ** NOTE: Overriding MIME types sent from the server can be obnoxious @@ -915,7 +920,7 @@ public static String guessContentTypeFromStream(InputStream is) throws IOException { - return("application/octet-stream"); + return ("application/octet-stream"); } /** @@ -930,9 +935,7 @@ { // Delayed initialization. if (fileNameMap == null) - { - fileNameMap = new MimeTypeMapper(); - } + fileNameMap = new MimeTypeMapper(); return fileNameMap; } @@ -945,7 +948,7 @@ * * @exception SecurityException If a security manager exists and its * checkSetFactory method doesn't allow the operation - * + * * @since 1.2 */ public static void setFileNameMap(FileNameMap map) @@ -958,7 +961,7 @@ fileNameMap = map; } - + // We don't put these in a static initializer, because it creates problems // with initializer co-dependency: SimpleDateFormat's constructors eventually // depend on URLConnection (via the java.text.*Symbols classes). @@ -968,10 +971,10 @@ return; Locale locale = new Locale("En", "Us", "Unix"); - dateFormat1 = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", - locale); - dateFormat2 = new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", - locale); + dateFormat1 = + new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'", locale); + dateFormat2 = + new SimpleDateFormat("EEEE, dd-MMM-yy hh:mm:ss 'GMT'", locale); dateFormat3 = new SimpleDateFormat("EEE MMM d hh:mm:ss yyyy", locale); dateformats_initialized = true; } Index: java/net/URLStreamHandler.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/net/URLStreamHandler.java,v retrieving revision 1.25 diff -u -r1.25 URLStreamHandler.java --- java/net/URLStreamHandler.java 12 Feb 2004 16:38:11 -0000 1.25 +++ java/net/URLStreamHandler.java 8 Apr 2004 16:53:15 -0000 @@ -7,7 +7,7 @@ it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + GNU Classpath 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 @@ -35,11 +35,11 @@ obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ - package java.net; -import java.io.IOException; import java.io.File; +import java.io.IOException; + /* * Written using on-line Java Platform 1.2 API Specification, as well @@ -57,7 +57,7 @@ * A protocol handler implementation should override the openConnection() * method, and optionally override the parseURL() and toExternalForm() * methods if necessary. (The default implementations will parse/write all - * URL's in the same form as http URL's). A protocol specific subclass + * URL's in the same form as http URL's). A protocol specific subclass * of URLConnection will most likely need to be created as well. *
* Note that the instance methods in this class are called as if they @@ -71,7 +71,7 @@ * * @author Aaron M. Renn (address@hidden) * @author Warren Levy (address@hidden) - * + * * @see URL */ public abstract class URLStreamHandler @@ -79,7 +79,7 @@ /** * Creates a URLStreamHander */ - public URLStreamHandler () + public URLStreamHandler() { } @@ -96,7 +96,7 @@ * * @exception IOException If an error occurs */ - protected abstract URLConnection openConnection(URL u) + protected abstract URLConnection openConnection(URL url) throws IOException; /** @@ -109,8 +109,8 @@ * position of the "#" character, which separates the "file" portion of * the URL from the "anchor" portion. *
- * This method assumes URL's are formatted like http protocol URL's, so - * subclasses that implement protocols with URL's the follow a different + * This method assumes URL's are formatted like http protocol URL's, so + * subclasses that implement protocols with URL's the follow a different * syntax should override this method. The lone exception is that if * the protocol name set in the URL is "file", this method will accept * an empty hostname (i.e., "file:///"), which is legal for that protocol @@ -126,28 +126,29 @@ int port = url.getPort(); String file = url.getFile(); String ref = url.getRef(); - - if (spec.regionMatches (start, "//", 0, 2)) + + if (spec.regionMatches(start, "//", 0, 2)) { String genuineHost; int hostEnd; - int colon, at_host; + int colon; + int at_host; start += 2; - int slash = spec.indexOf ('/', start); - if (slash >= 0) + int slash = spec.indexOf('/', start); + if (slash >= 0) hostEnd = slash; - else + else hostEnd = end; - host = spec.substring (start, hostEnd); - + host = spec.substring(start, hostEnd); + // We first need a genuine host name (with userinfo). // So we check for '@': if it's present check the port in the // section after '@' in the other case check it in the full string. // P.S.: We don't care having '@' at the beginning of the string. - if ((at_host = host.indexOf ('@')) >= 0) - genuineHost = host.substring (at_host); + if ((at_host = host.indexOf('@')) >= 0) + genuineHost = host.substring(at_host); else genuineHost = host; @@ -157,70 +158,70 @@ // this is undocumented and likely an unintended side effect in 1.2 // so we'll be simple here and stick with "". Note that // "http://" or "http:///" produce a "" host in JDK 1.2. - if ((colon = genuineHost.indexOf (':')) >= 0) + if ((colon = genuineHost.indexOf(':')) >= 0) { try { - port = Integer.parseInt (genuineHost.substring (colon + 1)); + port = Integer.parseInt(genuineHost.substring(colon + 1)); } catch (NumberFormatException e) { ; // Ignore invalid port values; port is already set to u's // port. } + // Now we must cut the port number in the original string. if (at_host >= 0) - host = host.substring (0, at_host + colon); + host = host.substring(0, at_host + colon); else - host = host.substring (0, colon); + host = host.substring(0, colon); } file = null; start = hostEnd; - } - else if (host == null) + } + else if (host == null) host = ""; if (file == null || file.length() == 0 - || (start < end && spec.charAt(start) == '/')) + || (start < end && spec.charAt(start) == '/')) { // No file context available; just spec for file. // Or this is an absolute path name; ignore any file context. file = spec.substring(start, end); ref = null; - } + } else if (start < end) { - // Context is available, but only override it if there is a new file. - char sepChar = '/'; - int lastSlash = file.lastIndexOf (sepChar); - if (lastSlash < 0 && File.separatorChar != sepChar - && url.getProtocol ().equals ("file")) - { - // On Windows, even '\' is allowed in a "file" URL. - sepChar = File.separatorChar; - lastSlash = file.lastIndexOf (sepChar); - } - - file = file.substring(0, lastSlash) - + sepChar + spec.substring (start, end); - - if (url.getProtocol ().equals ("file")) - { - // For "file" URLs constructed relative to a context, we - // need to canonicalise the file path. - try - { + // Context is available, but only override it if there is a new file. + char sepChar = '/'; + int lastSlash = file.lastIndexOf(sepChar); + if (lastSlash < 0 && File.separatorChar != sepChar + && url.getProtocol().equals("file")) + { + // On Windows, even '\' is allowed in a "file" URL. + sepChar = File.separatorChar; + lastSlash = file.lastIndexOf(sepChar); + } + + file = + file.substring(0, lastSlash) + sepChar + spec.substring(start, end); + + if (url.getProtocol().equals("file")) + { + // For "file" URLs constructed relative to a context, we + // need to canonicalise the file path. + try + { boolean endsWithSlash = file.charAt(file.length() - 1) == '/'; - file = new File (file).getCanonicalPath (); - if (endsWithSlash - && file.charAt(file.length() - 1) != '/') + file = new File(file).getCanonicalPath(); + if (endsWithSlash && file.charAt(file.length() - 1) != '/') file += '/'; - } - catch (IOException e) - { + } + catch (IOException e) + { // Do nothing. - } - } + } + } ref = null; } @@ -240,10 +241,9 @@ // XXX - Classpath used to call PlatformHelper.toCanonicalForm() on // the file part. It seems like overhead, but supposedly there is some // benefit in windows based systems (it also lowercased the string). - setURL(url, url.getProtocol(), host, port, file, ref); } - + /* * Canonicalize a filename. */ @@ -251,7 +251,6 @@ { // XXX - GNU Classpath has an implementation that might be more appropriate // for Windows based systems (gnu.java.io.PlatformHelper.toCanonicalForm) - int index; // Replace "/./" with "/". This probably isn't very efficient in @@ -270,7 +269,7 @@ else break; } - return file; + return file; } /** @@ -278,7 +277,7 @@ * * @param url1 The first url * @param url2 The second url to compare with the first - * + * * @return True if both URLs point to the same file, false otherwise. * * @specnote Now protected @@ -287,19 +286,21 @@ { if (url1 == url2) return true; + // This comparison is very conservative. It assumes that any // field can be null. if (url1 == null || url2 == null) return false; - int p1 = url1.getPort (); + int p1 = url1.getPort(); if (p1 == -1) - p1 = url1.ph.getDefaultPort (); - int p2 = url2.getPort (); + p1 = url1.ph.getDefaultPort(); + int p2 = url2.getPort(); if (p2 == -1) - p2 = url2.ph.getDefaultPort (); + p2 = url2.ph.getDefaultPort(); if (p1 != p2) return false; - String s1, s2; + String s1; + String s2; s1 = url1.getProtocol(); s2 = url2.getProtocol(); if (s1 != s2 && (s1 == null || ! s1.equals(s2))) @@ -333,7 +334,7 @@ * #setURL(URL,String,String,int,String,String,String,String); */ protected void setURL(URL u, String protocol, String host, int port, - String file, String ref) + String file, String ref) { u.set(protocol, host, port, file, ref); } @@ -355,8 +356,8 @@ * different from this one */ protected void setURL(URL u, String protocol, String host, int port, - String authority, String userInfo, String path, - String query, String ref) + String authority, String userInfo, String path, + String query, String ref) { u.set(protocol, host, port, authority, userInfo, path, query, ref); } @@ -372,32 +373,29 @@ * * @return True if both given URLs are equal, false otherwise. */ - protected boolean equals (URL url1, URL url2) + protected boolean equals(URL url1, URL url2) { // This comparison is very conservative. It assumes that any // field can be null. - return (url1.getPort () == url2.getPort () - && ((url1.getProtocol () == null && url2.getProtocol () == null) - || (url1.getProtocol () != null - && url1.getProtocol ().equals (url2.getProtocol ()))) - && ((url1.getUserInfo () == null && url2.getUserInfo () == null) - || (url1.getUserInfo () != null - && url1.getUserInfo ().equals(url2.getUserInfo ()))) - && ((url1.getAuthority () == null && url2.getAuthority () == null) - || (url1.getAuthority () != null - && url1.getAuthority ().equals(url2.getAuthority ()))) - && ((url1.getHost () == null && url2.getHost () == null) - || (url1.getHost () != null - && url1.getHost ().equals(url2.getHost ()))) - && ((url1.getPath () == null && url2.getPath () == null) - || (url1.getPath () != null - && url1.getPath ().equals (url2.getPath ()))) - && ((url1.getQuery () == null && url2.getQuery () == null) - || (url1.getQuery () != null - && url1.getQuery ().equals(url2.getQuery ()))) - && ((url1.getRef () == null && url2.getRef () == null) - || (url1.getRef () != null - && url1.getRef ().equals(url2.getRef ())))); + return (url1.getPort() == url2.getPort() + && ((url1.getProtocol() == null && url2.getProtocol() == null) + || (url1.getProtocol() != null + && url1.getProtocol().equals(url2.getProtocol()))) + && ((url1.getUserInfo() == null && url2.getUserInfo() == null) + || (url1.getUserInfo() != null + && url1.getUserInfo().equals(url2.getUserInfo()))) + && ((url1.getAuthority() == null && url2.getAuthority() == null) + || (url1.getAuthority() != null + && url1.getAuthority().equals(url2.getAuthority()))) + && ((url1.getHost() == null && url2.getHost() == null) + || (url1.getHost() != null && url1.getHost().equals(url2.getHost()))) + && ((url1.getPath() == null && url2.getPath() == null) + || (url1.getPath() != null && url1.getPath().equals(url2.getPath()))) + && ((url1.getQuery() == null && url2.getQuery() == null) + || (url1.getQuery() != null + && url1.getQuery().equals(url2.getQuery()))) + && ((url1.getRef() == null && url2.getRef() == null) + || (url1.getRef() != null && url1.getRef().equals(url2.getRef())))); } /** @@ -410,19 +408,19 @@ * * @exception UnknownHostException If an unknown host is found */ - protected boolean hostsEqual (URL url1, URL url2) + protected boolean hostsEqual(URL url1, URL url2) { - InetAddress addr1 = getHostAddress (url1); - InetAddress addr2 = getHostAddress (url2); + InetAddress addr1 = getHostAddress(url1); + InetAddress addr2 = getHostAddress(url2); if (addr1 != null && addr2 != null) - return addr1.equals (addr2); + return addr1.equals(addr2); String host1 = url1.getHost(); String host2 = url2.getHost(); - + if (host1 != null && host2 != null) - return host1.equalsIgnoreCase (host2); + return host1.equalsIgnoreCase(host2); return host1 == null && host2 == null; } @@ -435,16 +433,16 @@ * * @return The address of the hostname in url. */ - protected InetAddress getHostAddress (URL url) + protected InetAddress getHostAddress(URL url) { - String hostname = url.getHost (); + String hostname = url.getHost(); if (hostname.equals("")) return null; - + try { - return InetAddress.getByName (hostname); + return InetAddress.getByName(hostname); } catch (UnknownHostException e) { @@ -458,7 +456,7 @@ * * @return The default port number. */ - protected int getDefaultPort () + protected int getDefaultPort() { return -1; } @@ -468,15 +466,14 @@ * other protocols that have different requirements for hashCode calculation. * * @param url The URL to calc the hashcode for. - * + * * @return The hashcode for the given URL. */ - protected int hashCode (URL url) + protected int hashCode(URL url) { - return url.getProtocol ().hashCode () + - ((url.getHost () == null) ? 0 : url.getHost ().hashCode ()) + - url.getFile ().hashCode() + - url.getPort (); + return url.getProtocol().hashCode() + + ((url.getHost() == null) ? 0 : url.getHost().hashCode()) + + url.getFile().hashCode() + url.getPort(); } /** @@ -488,23 +485,27 @@ * * @return A string representation of the url */ - protected String toExternalForm(URL u) + protected String toExternalForm(URL url) { - String protocol, host, file, ref, user; + String protocol; + String host; + String file; + String ref; + String user; int port; - protocol = u.getProtocol(); + protocol = url.getProtocol(); // JDK 1.2 online doc infers that host could be null because it // explicitly states that file cannot be null, but is silent on host. - host = u.getHost(); + host = url.getHost(); if (host == null) host = ""; - port = u.getPort(); - file = u.getFile(); - ref = u.getRef(); - user = u.getUserInfo(); + port = url.getPort(); + file = url.getFile(); + ref = url.getRef(); + user = url.getUserInfo(); // Guess a reasonable size for the string buffer so we have to resize // at most once. @@ -520,13 +521,13 @@ if (host.length() != 0) { sb.append("//"); - if (user != null && !"".equals(user)) + if (user != null && ! "".equals(user)) sb.append(user).append('@'); sb.append(host); - // Append port if port was in URL spec. - if (port >= 0) - sb.append(':').append(port); + // Append port if port was in URL spec. + if (port >= 0) + sb.append(':').append(port); } sb.append(file);