public abstract class

URLConnection

extends URLConnection
java.lang.Object
   ↳ java.net.URLConnection
     ↳ sun.net.www.URLConnection
Known Direct Subclasses

Class Overview

A class to represent an active connection to an object represented by a URL.

Summary

Fields
protected MessageHeader properties
[Expand]
Inherited Fields
From class java.net.URLConnection
Public Constructors
URLConnection(URL u)
Create a URLConnection object.
Public Methods
void addRequestProperty(String key, String value)
The following three methods addRequestProperty, getRequestProperty, and getRequestProperties were copied from the superclass implementation before it was changed by CR:6230836, to maintain backward compatibility.
boolean canCache()
Returns true if the data associated with this URL can be cached.
void close()
Call this to close the connection and flush any remaining data.
int getContentLength()
Call this routine to get the content-length associated with this object.
String getContentType()
Call this routine to get the content-type associated with this object.
String getHeaderField(String name)
Returns the value of the named header field.
String getHeaderField(int n)
Return the value for the nth header field.
String getHeaderFieldKey(int n)
Return the key for the nth header field.
MessageHeader getProperties()
Call this routine to get the property list for this object.
Map<StringList<String>> getRequestProperties()
Returns an unmodifiable Map of general request properties for this connection.
String getRequestProperty(String key)
Returns the value of the named general request property for this connection.
synchronized static boolean isProxiedHost(String host)
void setContentType(String type)
Set the content type of this URL to a specific value.
void setProperties(MessageHeader properties)
Call this routine to set the property list for this object.
synchronized static void setProxiedHost(String host)
void setRequestProperty(String key, String value)
Sets the general request property.
Protected Methods
void setContentLength(int length)
Call this routine to set the content-length associated with this object.
[Expand]
Inherited Methods
From class java.net.URLConnection
From class java.lang.Object

Fields

protected MessageHeader properties

Public Constructors

public URLConnection (URL u)

Create a URLConnection object. These should not be created directly: instead they should be created by protocol handers in response to URL.openConnection.

Parameters
u The URL that this connects to.

Public Methods

public void addRequestProperty (String key, String value)

The following three methods addRequestProperty, getRequestProperty, and getRequestProperties were copied from the superclass implementation before it was changed by CR:6230836, to maintain backward compatibility.

Parameters
key the keyword by which the request is known (e.g., "accept").
value the value associated with it.

public boolean canCache ()

Returns true if the data associated with this URL can be cached.

public void close ()

Call this to close the connection and flush any remaining data. Overriders must remember to call super.close()

public int getContentLength ()

Call this routine to get the content-length associated with this object.

Returns
  • the content length of the resource that this connection's URL references, or -1 if the content length is not known.

public String getContentType ()

Call this routine to get the content-type associated with this object.

Returns
  • the content type of the resource that the URL references, or null if not known.

public String getHeaderField (String name)

Returns the value of the named header field.

If called on a connection that sets the same header multiple times with possibly different values, only the last value is returned.

Parameters
name the name of a header field.
Returns
  • the value of the named header field, or null if there is no such field in the header.

public String getHeaderField (int n)

Return the value for the nth header field. Returns null if there are fewer than n fields. This can be used in conjunction with getHeaderFieldKey to iterate through all the headers in the message.

Parameters
n an index, where n>=0
Returns
  • the value of the nth header field or null if there are fewer than n+1 fields

public String getHeaderFieldKey (int n)

Return the key for the nth header field. Returns null if there are fewer than n fields. This can be used to iterate through all the headers in the message.

Parameters
n an index, where n>=0
Returns
  • the key for the nth header field, or null if there are fewer than n+1 fields.

public MessageHeader getProperties ()

Call this routine to get the property list for this object. Properties (like content-type) that have explicit getXX() methods associated with them should be accessed using those methods.

public Map<StringList<String>> getRequestProperties ()

Returns an unmodifiable Map of general request properties for this connection. The Map keys are Strings that represent the request-header field names. Each Map value is a unmodifiable List of Strings that represents the corresponding field values.

Returns
  • a Map of the general request properties for this connection.

public String getRequestProperty (String key)

Returns the value of the named general request property for this connection.

Parameters
key the keyword by which the request is known (e.g., "accept").
Returns
  • the value of the named general request property for this connection. If key is null, then null is returned.

public static synchronized boolean isProxiedHost (String host)

public void setContentType (String type)

Set the content type of this URL to a specific value.

Parameters
type The content type to use. One of the content_* static variables in this class should be used. eg. setType(URL.content_html);

public void setProperties (MessageHeader properties)

Call this routine to set the property list for this object.

public static synchronized void setProxiedHost (String host)

public void setRequestProperty (String key, String value)

Sets the general request property. If a property with the key already exists, overwrite its value with the new value.

NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-seperated list syntax which enables multiple properties to be appended into a single property.

Parameters
key the keyword by which the request is known (e.g., "accept").
value the value associated with it.

Protected Methods

protected void setContentLength (int length)

Call this routine to set the content-length associated with this object.