Commit 95b88040 by Michael Koch Committed by Michael Koch

URLConnection.java: Reformatted.

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.

From-SVN: r88226
parent 1165dc50
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.
2004-09-27 Michael Koch <konqueror@gmx.de> 2004-09-27 Michael Koch <konqueror@gmx.de>
* java/io/BufferedInputStream.java * java/io/BufferedInputStream.java
......
...@@ -858,7 +858,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -858,7 +858,7 @@ public class URLClassLoader extends SecureClassLoader
// Just try to read it in all at once // Just try to read it in all at once
data = new byte[length]; data = new byte[length];
int pos = 0; int pos = 0;
while(length - pos > 0) while (length - pos > 0)
{ {
int len = in.read(data, pos, length - pos); int len = in.read(data, pos, length - pos);
if (len == -1) if (len == -1)
...@@ -872,7 +872,7 @@ public class URLClassLoader extends SecureClassLoader ...@@ -872,7 +872,7 @@ public class URLClassLoader extends SecureClassLoader
// We don't know the data length. // We don't know the data length.
// Have to read it in chunks. // Have to read it in chunks.
ByteArrayOutputStream out = new ByteArrayOutputStream(4096); ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
byte b[] = new byte[4096]; byte[] b = new byte[4096];
int l = 0; int l = 0;
while (l != -1) while (l != -1)
{ {
......
...@@ -35,6 +35,7 @@ this exception to your version of the library, but you are not ...@@ -35,6 +35,7 @@ this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */ exception statement from your version. */
package java.net; package java.net;
import java.io.IOException; import java.io.IOException;
...@@ -87,8 +88,8 @@ import gnu.gcj.io.MimeTypes; ...@@ -87,8 +88,8 @@ import gnu.gcj.io.MimeTypes;
* by the actual content handlers as described in the description of that * by the actual content handlers as described in the description of that
* method. * method.
* *
* @author Aaron M. Renn <arenn@urbanophile.com> * @author Aaron M. Renn (arenn@urbanophile.com)
* @author Warren Levy <warrenl@cygnus.com> * @author Warren Levy (warrenl@cygnus.com)
*/ */
public abstract class URLConnection public abstract class URLConnection
{ {
...@@ -370,7 +371,7 @@ public abstract class URLConnection ...@@ -370,7 +371,7 @@ public abstract class URLConnection
{ {
if (! dateformats_initialized) if (! dateformats_initialized)
initializeDateFormats(); initializeDateFormats();
if (position == null) if (position == null)
position = new ParsePosition(0); position = new ParsePosition(0);
...@@ -411,23 +412,29 @@ public abstract class URLConnection ...@@ -411,23 +412,29 @@ public abstract class URLConnection
} }
/** /**
* This method returns the content of the document pointed to by the URL * This method returns the content of the document pointed to by the
* as an Object. The type of object depends on the MIME type of the * URL as an Object. The type of object depends on the MIME type of
* object and particular content hander loaded. Most text type content * the object and particular content hander loaded. Most text type
* handlers will return a subclass of InputStream. Images usually return * content handlers will return a subclass of
* a class that implements ImageProducer. There is not guarantee what * <code>InputStream</code>. Images usually return a class that
* type of object will be returned, however. * implements <code>ImageProducer</code>. There is not guarantee
* <p> * what type of object will be returned, however.
* This class first determines the MIME type of the content, then creates *
* a ContentHandler object to process the input. If the ContentHandlerFactory * <p>This class first determines the MIME type of the content, then
* is set, then that object is called to load a content handler, otherwise * creates a ContentHandler object to process the input. If the
* a class called gnu.java.net.content.&lt;content_type&gt; is tried. * <code>ContentHandlerFactory</code> is set, then that object is
* The default class will also be used if the content handler factory returns * called to load a content handler, otherwise a class called
* a null content handler. * gnu.java.net.content.&lt;content_type&gt; is tried. If this
* * handler does not exist, the method will simple return the
* @exception IOException If an error occurs * <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 with the connection occurs.
* @exception UnknownServiceException If the protocol does not support the * @exception UnknownServiceException If the protocol does not support the
* content type * content type at all.
*/ */
public Object getContent() throws IOException public Object getContent() throws IOException
{ {
...@@ -441,10 +448,10 @@ public abstract class URLConnection ...@@ -441,10 +448,10 @@ public abstract class URLConnection
String type = getContentType(); String type = getContentType();
ContentHandler ch = getContentHandler(type); ContentHandler ch = getContentHandler(type);
if (ch == null) if (ch != null)
return getInputStream(); return ch.getContent(this);
return ch.getContent(this); return getInputStream();
} }
/** /**
...@@ -888,20 +895,20 @@ public abstract class URLConnection ...@@ -888,20 +895,20 @@ public abstract class URLConnection
*/ */
public static String guessContentTypeFromName(String filename) public static String guessContentTypeFromName(String filename)
{ {
int dot = filename.lastIndexOf ("."); int dot = filename.lastIndexOf(".");
if (dot != -1) if (dot != -1)
{ {
if (dot == filename.length()) if (dot == filename.length())
return ("application/octet-stream"); return "application/octet-stream";
else else
filename = filename.substring (dot + 1); filename = filename.substring(dot + 1);
} }
String type = MimeTypes.getMimeTypeFromExtension (filename); String type = MimeTypes.getMimeTypeFromExtension(filename);
if (type == null) if (type == null)
return("application/octet-stream"); return"application/octet-stream";
return type; return type;
} }
...@@ -957,7 +964,7 @@ public abstract class URLConnection ...@@ -957,7 +964,7 @@ public abstract class URLConnection
*/ */
public static void setFileNameMap(FileNameMap map) 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. // setting the factory.
SecurityManager s = System.getSecurityManager(); SecurityManager s = System.getSecurityManager();
if (s != null) if (s != null)
...@@ -968,12 +975,12 @@ public abstract class URLConnection ...@@ -968,12 +975,12 @@ public abstract class URLConnection
private ContentHandler getContentHandler(String contentType) private ContentHandler getContentHandler(String contentType)
{ {
ContentHandler handler;
// No content type so just handle it as the default. // No content type so just handle it as the default.
if (contentType == null || contentType.equals("")) if (contentType == null || contentType.equals(""))
return null; return null;
ContentHandler handler;
// See if a handler has been cached for this content type. // See if a handler has been cached for this content type.
// For efficiency, if a content type has been searched for but not // 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 // found, it will be in the hash table but as the contentType String
...@@ -1039,7 +1046,7 @@ public abstract class URLConnection ...@@ -1039,7 +1046,7 @@ public abstract class URLConnection
} }
// Update the hashtable with the new content handler. // Update the hashtable with the new content handler.
if (handler != null && handler instanceof ContentHandler) if (handler instanceof ContentHandler)
{ {
handlers.put(contentType, handler); handlers.put(contentType, handler);
return handler; return handler;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment