Save This Page
Home » apache-harmony-6.0-src-r917296-snapshot » java » net » [javadoc | source]
java.net
abstract public class: URLConnection [javadoc | source]
java.lang.Object
   java.net.URLConnection

Direct Known Subclasses:
    HttpsURLConnection, HttpURLConnection, JarURLConnection

Concrete implementations of the abstract {@code URLConnection} class provide a communication link to a URL for exchanging data with a specific protocol type. A {@code URLConnection} can only be set up after the instantiation but before connecting to the remote resource.
Nested Class Summary:
static class  URLConnection.DefaultContentHandler   
Field Summary
protected  URL url    The URL which represents the remote target of this {@code URLConnection}. 
 ContentHandler defaultHandler     
protected  long ifModifiedSince    The data must be modified more recently than this time in milliseconds since January 1, 1970, GMT to be transmitted. 
protected  boolean useCaches    Specifies whether the using of caches is enabled or the data has to be recent for every request. 
protected  boolean connected    Specifies whether this {@code URLConnection} is already connected to the remote resource. If this field is set to {@code true} the flags for setting up the connection are not changeable anymore. 
protected  boolean doOutput    Specifies whether this {@code URLConnection} allows sending data. 
protected  boolean doInput    Specifies whether this {@code URLConnection} allows receiving data. 
protected  boolean allowUserInteraction    Specifies whether this {@code URLConnection} allows user interaction as it is needed for authentication purposes. 
static  Hashtable<String, Object> contentHandlers    Cache for storing content handler 
Constructor:
 protected URLConnection(URL url) 
    Creates a new {@code URLConnection} instance pointing to the resource specified by the given URL.
    Parameters:
    url - the URL which represents the resource this {@code URLConnection} will point to.
Method from java.net.URLConnection Summary:
addRequestProperty,   connect,   getAllowUserInteraction,   getConnectTimeout,   getContent,   getContent,   getContentEncoding,   getContentLength,   getContentType,   getDate,   getDefaultAllowUserInteraction,   getDefaultRequestProperty,   getDefaultUseCaches,   getDoInput,   getDoOutput,   getExpiration,   getFileNameMap,   getHeaderField,   getHeaderField,   getHeaderFieldDate,   getHeaderFieldInt,   getHeaderFieldKey,   getHeaderFields,   getIfModifiedSince,   getInputStream,   getLastModified,   getOutputStream,   getPermission,   getReadTimeout,   getRequestProperties,   getRequestProperty,   getURL,   getUseCaches,   guessContentTypeFromName,   guessContentTypeFromStream,   setAllowUserInteraction,   setConnectTimeout,   setContentHandlerFactory,   setDefaultAllowUserInteraction,   setDefaultRequestProperty,   setDefaultUseCaches,   setDoInput,   setDoOutput,   setFileNameMap,   setIfModifiedSince,   setReadTimeout,   setRequestProperty,   setUseCaches,   toString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.net.URLConnection Detail:
 public  void addRequestProperty(String field,
    String newValue) 
    Adds the given property to the request header. Existing properties with the same name will not be overwritten by this method.
 abstract public  void connect() throws IOException
    Establishes the connection to the earlier configured resource. The connection can only be set up before this method has been called.
 public boolean getAllowUserInteraction() 
    Gets the option value which indicates whether user interaction is allowed on this {@code URLConnection}.
 public int getConnectTimeout() 
    Gets the configured connecting timeout.
 public Object getContent() throws IOException 
    Gets an object representing the content of the resource this {@code URLConnection} is connected to. First, it attempts to get the content type from the method {@code getContentType()} which looks at the response header field "Content-Type". If none is found it will guess the content type from the filename extension. If that fails the stream itself will be used to guess the content type.
 public Object getContent(Class[] types) throws IOException 
    Gets an object representing the content of the resource this {@code URLConnection} is connected to. First, it attempts to get the content type from the method {@code getContentType()} which looks at the response header field "Content-Type". If none is found it will guess the content type from the filename extension. If that fails the stream itself will be used to guess the content type. The content type must match with one of the list {@code types}.
 public String getContentEncoding() 
    Gets the content encoding type specified by the response header field {@code content-encoding} or {@code null} if this field is not set.
 public int getContentLength() 
    Gets the content length in bytes specified by the response header field {@code content-length} or {@code -1} if this field is not set.
 public String getContentType() 
    Gets the MIME-type of the content specified by the response header field {@code content-type} or {@code null} if type is unknown.
 public long getDate() 
    Gets the timestamp when this response has been sent as a date in milliseconds since January 1, 1970 GMT or {@code 0} if this timestamp is unknown.
 public static boolean getDefaultAllowUserInteraction() 
    Gets the default setting whether this connection allows user interaction.
 public static String getDefaultRequestProperty(String field) 
Deprecated! Use - #getRequestProperty

    Gets the default value for the specified request {@code field} or {@code null} if the field could not be found. The current implementation of this method returns always {@code null}.
 public boolean getDefaultUseCaches() 
    Gets the default setting whether this connection allows using caches.
 public boolean getDoInput() 
    Gets the value of the option {@code doInput} which specifies whether this connection allows to receive data.
 public boolean getDoOutput() 
    Gets the value of the option {@code doOutput} which specifies whether this connection allows to send data.
 public long getExpiration() 
    Gets the timestamp when this response will be expired in milliseconds since January 1, 1970 GMT or {@code 0} if this timestamp is unknown.
 public static FileNameMap getFileNameMap() 
    Gets the table which is used by all {@code URLConnection} instances to determine the MIME-type according to a file extension.
 public String getHeaderField(int pos) 
    Gets the header value at the field position {@code pos} or {@code null} if the header has fewer than {@code pos} fields. The current implementation of this method returns always {@code null}.
 public String getHeaderField(String key) 
    Gets the value of the header field specified by {@code key} or {@code null} if there is no field with this name. The current implementation of this method returns always {@code null}.
 public long getHeaderFieldDate(String field,
    long defaultValue) 
    Gets the specified header value as a date in milliseconds since January 1, 1970 GMT. Returns the {@code defaultValue} if no such header field could be found.
 public int getHeaderFieldInt(String field,
    int defaultValue) 
    Gets the specified header value as a number. Returns the {@code defaultValue} if no such header field could be found or the value could not be parsed as an {@code Integer}.
 public String getHeaderFieldKey(int posn) 
    Gets the name of the header field at the given position {@code posn} or {@code null} if there are fewer than {@code posn} fields. The current implementation of this method returns always {@code null}.
 public Map<String> getHeaderFields() 
    Gets an unchangeable map of the response-header fields and values. The response-header field names are the key values of the map. The map values are lists of header field values associated with a particular key name.
 public long getIfModifiedSince() 
    Gets the point of time since when the data must be modified to be transmitted. Some protocols transmit data only if it has been modified more recently than a particular time.
 public InputStream getInputStream() throws IOException 
    Gets an {@code InputStream} for reading data from the resource pointed by this {@code URLConnection}. It throws an UnknownServiceException by default. This method must be overridden by its subclasses.
 public long getLastModified() 
    Gets the value of the response header field {@code last-modified} or {@code 0} if this value is not set.
 public OutputStream getOutputStream() throws IOException 
    Gets an {@code OutputStream} for writing data to this {@code URLConnection}. It throws an {@code UnknownServiceException} by default. This method must be overridden by its subclasses.
 public Permission getPermission() throws IOException 
    Gets a {@code Permission} object representing all needed permissions to open this connection. The returned permission object depends on the state of the connection and will be {@code null} if no permissions are necessary. By default, this method returns {@code AllPermission}. Subclasses should overwrite this method to return an appropriate permission object.
 public int getReadTimeout() 
    Gets the configured timeout for reading from the input stream of an established connection to the resource.
 public Map<String> getRequestProperties() 
    Gets an unchangeable map of general request properties used by this connection. The request property names are the key values of the map. The map values are lists of property values of the corresponding key name.
 public String getRequestProperty(String field) 
    Gets the value of the request header property specified by {code field} or {@code null} if there is no field with this name. The current implementation of this method returns always {@code null}.
 public URL getURL() 
    Gets the URL represented by this {@code URLConnection}.
 public boolean getUseCaches() 
    Gets the value of the flag which specifies whether this {@code URLConnection} allows to use caches.
 public static String guessContentTypeFromName(String url) 
    Determines the MIME-type of the given resource {@code url} by resolving the filename extension with the internal FileNameMap. Any fragment identifier is removed before processing.
 public static String guessContentTypeFromStream(InputStream is) throws IOException 
    Determines the MIME-type of the resource represented by the input stream {@code is} by reading its first few characters.
 public  void setAllowUserInteraction(boolean newValue) 
    Sets the flag indicating whether this connection allows user interaction or not. This method can only be called prior to the connection establishment.
 public  void setConnectTimeout(int timeout) 
    Sets the timeout value in milliseconds for establishing the connection to the resource pointed by this {@code URLConnection} instance. A {@code SocketTimeoutException} is thrown if the connection could not be established in this time. Default is {@code 0} which stands for an infinite timeout.
 public static synchronized  void setContentHandlerFactory(ContentHandlerFactory contentFactory) 
    Sets the internally used content handler factory. The content factory can only be set if it is allowed by the security manager and only once during the lifetime of the application.
 public static  void setDefaultAllowUserInteraction(boolean allows) 
    Sets the default value for the flag indicating whether this connection allows user interaction or not. Existing {@code URLConnection}s are unaffected.
 public static  void setDefaultRequestProperty(String field,
    String value) 
Deprecated! Use - #setRequestProperty of an existing {@code URLConnection} instance.

    Sets the default value of the specified request header field. This value will be used for the specific field of every newly created connection. The current implementation of this method does nothing.
 public  void setDefaultUseCaches(boolean newValue) 
    Sets the default value for the flag indicating whether this connection allows to use caches. Existing {@code URLConnection}s are unaffected.
 public  void setDoInput(boolean newValue) 
    Sets the flag indicating whether this {@code URLConnection} allows input. It cannot be set after the connection is established.
 public  void setDoOutput(boolean newValue) 
    Sets the flag indicating whether this {@code URLConnection} allows output. It cannot be set after the connection is established.
 public static  void setFileNameMap(FileNameMap map) 
    Sets the internal map which is used by all {@code URLConnection} instances to determine the MIME-type according to a filename extension.
 public  void setIfModifiedSince(long newValue) 
    Sets the point of time since when the data must be modified to be transmitted. Some protocols transmit data only if it has been modified more recently than a particular time. The data will be transmitted regardless of its timestamp if this option is set to {@code 0}.
 public  void setReadTimeout(int timeout) 
    Sets the timeout value in milliseconds for reading from the input stream of an established connection to the resource. A {@code SocketTimeoutException} is thrown if the connection could not be established in this time. Default is {@code 0} which stands for an infinite timeout.
 public  void setRequestProperty(String field,
    String newValue) 
    Sets the value of the specified request header field. The value will only be used by the current {@code URLConnection} instance. This method can only be called before the connection is established.
 public  void setUseCaches(boolean newValue) 
    Sets the flag indicating whether this connection allows to use caches or not. This method can only be called prior to the connection establishment.
 public String toString() 
    Returns the string representation containing the name of this class and the URL.