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
This commit is contained in:
parent
1165dc50e8
commit
95b88040e2
@ -1,3 +1,10 @@
|
||||
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>
|
||||
|
||||
* java/io/BufferedInputStream.java
|
||||
|
@ -858,7 +858,7 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// 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 @@ public class URLClassLoader extends SecureClassLoader
|
||||
// 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)
|
||||
{
|
||||
|
@ -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
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.net;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -87,8 +88,8 @@ import gnu.gcj.io.MimeTypes;
|
||||
* 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 @@ public abstract class URLConnection
|
||||
{
|
||||
if (! dateformats_initialized)
|
||||
initializeDateFormats();
|
||||
|
||||
|
||||
if (position == null)
|
||||
position = new ParsePosition(0);
|
||||
|
||||
@ -411,23 +412,29 @@ public abstract class URLConnection
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @exception IOException If an error occurs
|
||||
* <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
|
||||
{
|
||||
@ -441,10 +448,10 @@ public abstract class URLConnection
|
||||
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 abstract class URLConnection
|
||||
*/
|
||||
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 abstract class URLConnection
|
||||
*/
|
||||
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 @@ public abstract class URLConnection
|
||||
|
||||
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 @@ public abstract class URLConnection
|
||||
}
|
||||
|
||||
// Update the hashtable with the new content handler.
|
||||
if (handler != null && handler instanceof ContentHandler)
|
||||
if (handler instanceof ContentHandler)
|
||||
{
|
||||
handlers.put(contentType, handler);
|
||||
return handler;
|
||||
|
Loading…
Reference in New Issue
Block a user