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;
* 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
{
{
if (! dateformats_initialized)
initializeDateFormats();
-
+
if (position == null)
position = new ParsePosition(0);
}
/**
- * 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.
- *
- * @exception IOException If an error occurs
+ * 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 with the connection occurs.
* @exception UnknownServiceException If the protocol does not support the
- * content type
+ * content type at all.
*/
public Object getContent() throws IOException
{
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();
}
/**
*/
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;
}
*/
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)
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
}
// Update the hashtable with the new content handler.
- if (handler != null && handler instanceof ContentHandler)
+ if (handler instanceof ContentHandler)
{
handlers.put(contentType, handler);
return handler;