[Patch] java.net - URL stuff

Michael Koch konqueror@gmx.de
Tue Sep 28 18:17:00 GMT 2004


Hi list,


I just commited the attached patch from merge java.net.URL a little bit
more with classpath.


Michael


2004-09-28  Michael Koch  <konqueror@gmx.de>

	* java/net/URLConnection.java: Reformatted.
	* java/net/URLClassLoader.java: Reformatted.
	(getContent): Reordered return of content.
	(getContentHandler): Don't check for null explicitely.

-------------- next part --------------
Index: java/net/URLConnection.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLConnection.java,v
retrieving revision 1.33
diff -u -r1.33 URLConnection.java
--- java/net/URLConnection.java	23 Jul 2004 01:21:40 -0000	1.33
+++ java/net/URLConnection.java	28 Sep 2004 11:01:45 -0000
@@ -35,6 +35,7 @@
 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;
@@ -87,8 +88,8 @@
  * by the actual content handlers as described in the description of that
  * method.
  *
- * @author Aaron M. Renn <arenn@urbanophile.com>
- * @author Warren Levy <warrenl@cygnus.com>
+ * @author Aaron M. Renn (arenn@urbanophile.com)
+ * @author Warren Levy (warrenl@cygnus.com)
  */
 public abstract class URLConnection
 {
@@ -370,7 +371,7 @@
   {
     if (! dateformats_initialized)
       initializeDateFormats();
-    
+
     if (position == null)
       position = new ParsePosition(0);
 
@@ -411,23 +412,29 @@
   }
 
   /**
-   * This method returns the content of the document pointed to by the URL
-   * as an Object.  The type of object depends on the MIME type of the
-   * object and particular content hander loaded.  Most text type content
-   * handlers will return a subclass of InputStream.  Images usually return
-   * a class that implements ImageProducer.  There is not guarantee what
-   * type of object will be returned, however.
-   * <p>
-   * This class first determines the MIME type of the content, then creates
-   * a ContentHandler object to process the input.  If the ContentHandlerFactory
-   * is set, then that object is called to load a content handler, otherwise
-   * a class called gnu.java.net.content.<content_type> is tried.
-   * The default class will also be used if the content handler factory returns
-   * a null content handler.
+   * This method returns the content of the document pointed to by the
+   * URL as an Object.  The type of object depends on the MIME type of
+   * the object and particular content hander loaded.  Most text type
+   * content handlers will return a subclass of
+   * <code>InputStream</code>.  Images usually return a class that
+   * implements <code>ImageProducer</code>.  There is not guarantee
+   * what type of object will be returned, however.
+   *
+   * <p>This class first determines the MIME type of the content, then
+   * creates a ContentHandler object to process the input.  If the
+   * <code>ContentHandlerFactory</code> is set, then that object is
+   * called to load a content handler, otherwise a class called
+   * gnu.java.net.content.<content_type> is tried.  If this
+   * handler does not exist, the method will simple return the
+   * <code>InputStream</code> returned by
+   * <code>getInputStream()</code>.  Note that the default
+   * implementation of <code>getInputStream()</code> throws a
+   * <code>UnknownServiceException</code> so subclasses are encouraged
+   * to override this method.</p>
    *
-   * @exception IOException If an error occurs
+   * @exception IOException If an error with the connection occurs.
    * @exception UnknownServiceException If the protocol does not support the
-   * content type
+   * content type at all.
    */
   public Object getContent() throws IOException
   {
@@ -441,10 +448,10 @@
     String type = getContentType();
     ContentHandler ch = getContentHandler(type);
 
-    if (ch == null)
-      return getInputStream();
+    if (ch != null)
+      return ch.getContent(this);
 
-    return ch.getContent(this);
+    return getInputStream();
   }
 
   /**
@@ -888,20 +895,20 @@
    */
   public static String guessContentTypeFromName(String filename)
   {
-    int dot = filename.lastIndexOf (".");
+    int dot = filename.lastIndexOf(".");
     
     if (dot != -1)
       {
 	if (dot == filename.length())
-	  return ("application/octet-stream");
+	  return "application/octet-stream";
 	else
-	  filename = filename.substring (dot + 1);
+	  filename = filename.substring(dot + 1);
       }
     
-    String type = MimeTypes.getMimeTypeFromExtension (filename);
+    String type = MimeTypes.getMimeTypeFromExtension(filename);
     
     if (type == null)
-      return("application/octet-stream");
+      return"application/octet-stream";
 
     return type;
   }
@@ -957,7 +964,7 @@
    */
   public static void setFileNameMap(FileNameMap map)
   {
-    // Throw an exception if an extant security mgr precludes
+    // Throw an exception if an extant security manager precludes
     // setting the factory.
     SecurityManager s = System.getSecurityManager();
     if (s != null)
@@ -968,12 +975,12 @@
 
   private ContentHandler getContentHandler(String contentType)
   {
-    ContentHandler handler;
-
     // No content type so just handle it as the default.
     if (contentType == null || contentType.equals(""))
       return null;
 
+    ContentHandler handler;
+
     // See if a handler has been cached for this content type.
     // For efficiency, if a content type has been searched for but not
     // found, it will be in the hash table but as the contentType String
@@ -1039,7 +1046,7 @@
       }
 
     // Update the hashtable with the new content handler.
-    if (handler != null && handler instanceof ContentHandler)
+    if (handler instanceof ContentHandler)
       {
 	handlers.put(contentType, handler);
 	return handler;
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.17
diff -u -r1.17 URLClassLoader.java
--- java/net/URLClassLoader.java	20 Apr 2004 13:05:10 -0000	1.17
+++ java/net/URLClassLoader.java	28 Sep 2004 11:01:45 -0000
@@ -858,7 +858,7 @@
 	    // 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)
@@ -872,7 +872,7 @@
 	    // 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)
 	      {


More information about the Java-patches mailing list