Additional top-level class in compilation unit: UnknownContentHandler.
URLConnection is the superclass
of all classes that represent a communications link between the
application and a URL. Instances of this class can be used both to
read from and to write to the resource referenced by the URL.
In general, creating a connection to a URL is a multistep process:
openConnection method on a URL.
connect method.
The setup parameters are modified using the following methods:
setAllowUserInteraction
setDoInput
setDoOutput
setIfModifiedSince
setUseCaches
and the general request properties are modified using the method:
setRequestProperty
Default values for the AllowUserInteraction and
UseCaches parameters can be set using the methods
setDefaultAllowUserInteraction and
setDefaultUseCaches.
Each of the above set methods has a corresponding
get method to retrieve the value of the parameter or
general request property. The specific parameters and general
request properties that are applicable are protocol specific.
The following methods are used to access the header fields and the contents after the connection is made to the remote object:
getContent
getHeaderField
getInputStream
getOutputStream
Certain header fields are accessed frequently. The methods:
getContentEncoding
getContentLength
getContentType
getDate
getExpiration
getLastModified
provide convenient access to these fields. The
getContentType method is used by the
getContent method to determine the type of the remote
object; subclasses may find it convenient to override the
getContentType method.
In the common case, all of the pre-connection parameters and
general request properties can be ignored: the pre-connection
parameters and request properties default to sensible values. For
most clients of this interface, there are only two interesting
methods: getInputStream and getContent,
which are mirrored in the URL class by convenience methods.
More information on the request properties and header fields of
an http connection can be found at:
Invoking thehttp://www.ietf.org/rfc/rfc2616.txt
close() methods on the InputStream or OutputStream of an
URLConnection after a request may free network resources associated with this
instance, unless particular protocol specifications specify different behaviours
for it.
java.net.URL#openConnection() , java.net.URLConnection#connect() , java.net.URLConnection#getContent() , java.net.URLConnection#getContentEncoding() , java.net.URLConnection#getContentLength() , java.net.URLConnection#getContentType() , java.net.URLConnection#getDate() , java.net.URLConnection#getExpiration() , java.net.URLConnection#getHeaderField(int) , java.net.URLConnection#getHeaderField(java.lang.String) , java.net.URLConnection#getInputStream() , java.net.URLConnection#getLastModified() , java.net.URLConnection#getOutputStream() , java.net.URLConnection#setAllowUserInteraction(boolean) , java.net.URLConnection#setDefaultUseCaches(boolean) , java.net.URLConnection#setDoInput(boolean) , java.net.URLConnection#setDoOutput(boolean) , java.net.URLConnection#setIfModifiedSince(long) , java.net.URLConnection#setRequestProperty(java.lang.String, java.lang.String) , java.net.URLConnection#setUseCaches(boolean)
| Modifier and Type | Field and Description |
|---|---|
| protected boolean | allowUserInteraction
If |
| protected boolean | connected
If |
| private int | |
| private static final String | |
| private static final String | |
| private static boolean | |
| private static final ConcurrentHashMap | |
| private static volatile boolean | |
| protected boolean | doInput
This variable is set by the |
| protected boolean | doOutput
This variable is set by the |
| private static volatile ContentHandlerFactory | factory
The ContentHandler factory. |
| private static volatile FileNameMap | |
| private static final Hashtable | |
| protected long | ifModifiedSince
Some protocols support skipping the fetching of the object unless the object has been modified more recently than a certain time. |
| private int | |
| private MessageHeader | |
| protected URL | url
The URL represents the remote object on the World Wide Web to which this connection is opened. |
| protected boolean | useCaches
If |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public void | addRequestProperty(String
the keyword by which the request is known
(e.g., " key, String Accept").the value associated with it. value)Adds a general request property specified by a key-value pair. |
| private void | |
| private static boolean | |
| public abstract void | connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established. |
| public boolean | Returns: the value of theallowUserInteraction field for
this object.Returns the value of the |
| public int | Returns: anint that indicates the connect timeout
value in millisecondsReturns setting for connect timeout. |
| public Object | Returns: the object fetched. Theinstanceof operator
should be used to determine the specific kind of object
returned.Retrieves the contents of this URL connection. |
| public Object | Returns: the object fetched that is the first match of the type specified in the classes array. null if none of the requested types are supported. Theinstanceof operator should be used to
determine the specific kind of object returned.the classes)Class array
indicating the requested typesRetrieves the contents of this URL connection. |
| public String | Returns: the content encoding of the resource that the URL references, ornull if not known.Returns the value of the |
| private ContentHandler | |
| private String | getContentHandlerPkgPrefixes()
Returns a vertical bar separated list of package prefixes for potential content handlers. |
| public int | Returns: the content length of the resource that this connection's URL references,-1 if the content length is not known,
or if the content length is greater than Integer.MAX_VALUE.Returns the value of the |
| public long | Returns: the content length of the resource that this connection's URL references, or-1 if the content length is
not known.Returns the value of the |
| public String | Returns: the content type of the resource that the URL references, ornull if not known.Returns the value of the |
| public long | Returns: the sending date of the resource that the URL references, or0 if not known. The value returned is the
number of milliseconds since January 1, 1970 GMT.Returns the value of the |
| public static boolean | Returns: the default value of theallowUserInteraction
field.Returns the default value of the |
| public static String | Returns: the value of the default request property for the specified key.the keyword by which the request is known (e.g., "Accept"). key)
Deprecated
The instance specific getRequestProperty method
should be used after an appropriate instance of URLConnection
is obtained.
Returns the value of the default request property. |
| public boolean | Returns: the default value of aURLConnection's
useCaches flag.Returns the default value of a |
| public static boolean | Returns: the default value of theuseCaches flag for the given protocol.the protocol whose defaultUseCaches setting is required protocol)Returns the default value of the |
| public boolean | Returns: the value of thisURLConnection's
doInput flag.Returns the value of this |
| public boolean | Returns: the value of thisURLConnection's
doOutput flag.Returns the value of this |
| public long | Returns: the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.Returns the value of the |
| public static FileNameMap | |
| public String | Returns: the value of the named header field, ornull
if there is no such field in the header.the name of a header field. name)Returns the value of the named header field. |
| public String | Returns: the value of thenth header field
or null if there are fewer than n+1 fieldsan index, where n)n>=0Returns the value for the |
| public long | Returns: the value of the field, parsed as a date. The value of thedefaultValue argument is returned if the field is
missing or malformed.the name of the header field. name, long a default value. defaultValue)Returns the value of the named field parsed as date. |
| public int | Returns: the value of the named field, parsed as an integer. ThedefaultValue value is returned if the field is
missing or malformed.the name of the header field. name, int the default value. defaultValue)Returns the value of the named field parsed as a number. |
| public String | Returns: the key for thenth header field,
or null if there are fewer than n+1
fields when n > 0.an index, where n)n>=0Returns the key for the |
| public long | Returns: the value of the named field, parsed as a long. ThedefaultValue value is returned if the field is
missing or malformed.the name of the header field. name, long the default value. defaultValue)Returns the value of the named field parsed as a number. |
| public Map | |
| public long | Returns: the value of this object'sifModifiedSince field.Returns the value of this object's |
| public InputStream | Returns: an input stream that reads from this open connection.Returns an input stream that reads from this open connection. |
| public long | Returns: the date the resource referenced by thisURLConnection was last modified, or 0 if not known.Returns the value of the |
| public OutputStream | Returns: an output stream that writes to this connection.Returns an output stream that writes to this connection. |
| public Permission | Returns: the permission object representing the permission necessary to make the connection represented by this URLConnection.
Deprecated
for removal since 25. Permissions can no longer be used for controlling access to resources
as the Security Manager is no longer supported.
Returns a permission object representing the permission necessary to make the connection represented by this object. |
| public int | Returns: anint that indicates the read timeout
value in millisecondsReturns setting for read timeout. |
| public Map | Returns: a Map of the general request properties for this connection.Returns an unmodifiable Map of general request properties for this connection. |
| public String | Returns: the value of the named general request property for this connection. If key is null, then null is returned.the keyword by which the request is known (e.g., "Accept"). key)Returns the value of the named general request property for this connection. |
| public URL | Returns: the value of thisURLConnection's URL
field.Returns the value of this |
| public boolean | Returns: the value of thisURLConnection's
useCaches field.Returns the value of this |
| public static String | Returns: a guess as to what the content type of the object is, based upon its file name.a filename. fname)Tries to determine the content type of an object, based on the specified "file" component of a URL. |
| public static String | Returns: a guess at the content type, ornull if none
can be determined.an input stream that supports marks. is)Tries to determine the type of an input stream based on the characters at the beginning of the input stream. |
| private ContentHandler | lookupContentHandlerClassFor(String contentType)
Looks for a content handler in a user-definable set of places. |
| private ContentHandler | |
| private static int | readBytes(int[] c, int len, InputStream is)
Tries to read the specified number of bytes from the stream Returns -1, If EOF is reached before len bytes are read, returns 0 otherwise |
| public void | setAllowUserInteraction(boolean
the new value. allowuserinteraction)Set the value of the |
| public void | setConnectTimeout(int
an timeout)int that specifies the connect
timeout value in millisecondsSets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. |
| public static synchronized void | setContentHandlerFactory(ContentHandlerFactory
the desired factory. fac)Sets the |
| public static void | setDefaultAllowUserInteraction(boolean
the new value. defaultallowuserinteraction)Sets the default value of the
|
| public static void | setDefaultRequestProperty(String
the keyword by which the request is known
(e.g., " key, String Accept").the value associated with the key. value)
Deprecated
The instance specific setRequestProperty method
should be used after an appropriate instance of URLConnection
is obtained. Invoking this method will have no effect.
Sets the default value of a general request property. |
| public void | setDefaultUseCaches(boolean
the new value. defaultusecaches)Sets the default value of the |
| public static void | setDefaultUseCaches(String
the protocol to set the default for protocol, boolean whether caching is enabled by default for the given protocol defaultVal)Sets the default value of the |
| public void | setDoInput(boolean
the new value. doinput)Sets the value of the |
| public void | setDoOutput(boolean
the new value. dooutput)Sets the value of the |
| public static void | |
| public void | setIfModifiedSince(long
the new value. ifmodifiedsince)Sets the value of the |
| public void | setReadTimeout(int
an timeout)int that specifies the timeout
value to be used in millisecondsSets the read timeout to a specified timeout, in milliseconds. |
| public void | setRequestProperty(String
the keyword by which the request is known
(e.g., " key, String Accept").the value associated with it. value)Sets the general request property. |
| public void | setUseCaches(boolean
a usecaches)boolean indicating whether
or not to allow cachingSets the value of the |
| private static long | skipForward(InputStream is, long toSkip)
Skips through the specified number of bytes from the stream until either EOF is reached, or the specified number of bytes have been skipped |
| private String | |
| public String | Returns: a string representation of thisURLConnection.Overrides java. Returns a |
| private String | typeToPackageName(String contentType)
Utility function to map a MIME content type into an equivalent pair of class name components. |