| java.lang.Object | |
| ↳ | java.net.URLConnection |
Known Direct Subclasses
|
Known Indirect Subclasses
|
The URLConnection class is responsible for establishing a connection to an
URL for a given protocol. The correct URLConnection subclass to call is
determined by URLStreamHandler.openConnection().
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| allowUserInteraction | |||||||||||
| connected | |||||||||||
| doInput | |||||||||||
| doOutput | |||||||||||
| ifModifiedSince | |||||||||||
| url | |||||||||||
| useCaches | |||||||||||
| Protected Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Creates a URLConnection pointing to the resource specified by the
url
| |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds the given request property.
| |||||||||||
Establishes the connection to the resource specified by this
URL with this method, along with other
options that can only be set before this connection is made. | |||||||||||
Returns the value of
allowUserInteraction which indicates
if this connection allows user interaction | |||||||||||
Returns a timeout of connection by milliseconds
| |||||||||||
Returns the object pointed to by this
URL. | |||||||||||
Returns the object pointed to by this
URL. | |||||||||||
Returns the Content encoding type of the response body, null if no such
field is found in the header response.
| |||||||||||
Returns the length of the content or body in the response header in
bytes.
| |||||||||||
Returns the type of the content.
| |||||||||||
Returns the date in milliseconds since epoch when this response header
was created, or 0 if the field
Date is not found in the
header. | |||||||||||
Returns whether this connection allow user interaction by default.
| |||||||||||
This method is deprecated.
Use getRequestProperty(String)
| |||||||||||
Returns whether this connection use caches by default.
| |||||||||||
Returns whether this connection supports input.
| |||||||||||
Returns whether this connection supports output.
| |||||||||||
Returns the date in milliseconds since epoch when this response header
expires or 0 if the field
Expires is not found in the
header. | |||||||||||
Returns the MIME table of this URL connection.
| |||||||||||
Returns the value of the field at position
pos | |||||||||||
Returns the value of the field corresponding to the
key
Returns null if there is no such field. | |||||||||||
Returns the date value in the form of milliseconds since epoch
corresponding to the field
field. | |||||||||||
Returns the integer value of the specified field.
| |||||||||||
Returns the name of the field at position specified by
posn,
null if there are fewer than posn fields. | |||||||||||
Provides an unmodifiable map of the connection header values.
| |||||||||||
Returns the value of
ifModifiedSince of this connection in
milliseconds since epoch | |||||||||||
Creates an InputStream for reading from this URL Connection.
| |||||||||||
Returns the value of the field
Last-Modified in the
response header, 0 if no such field exists | |||||||||||
Creates an OutputStream for writing to this URL Connection.
| |||||||||||
Returns the permissions necessary to make the connection.
| |||||||||||
Returns a timeout of reading by milliseconds
| |||||||||||
Provides an unmodifiable map of the request properties.
| |||||||||||
Returns the value corresponding to the field in the request Header, null
if no such field exists.
| |||||||||||
Returns the
URL of this connection | |||||||||||
Returns whether this connection uses caches
| |||||||||||
Determines the MIME type of the file specified by the
string URL, using the filename extension. | |||||||||||
Examines the bytes of the input stream and returns the MIME type, null if
no content type can be deduced.
| |||||||||||
Sets the flag indicating whether this connection allows user interaction
This can only be called prior to connection establishment.
| |||||||||||
Sets a timeout for connection to perform non-block.
| |||||||||||
Sets the current content handler factory to be
contentFactory. | |||||||||||
Set whether user interaction is allowed by default.
| |||||||||||
This method is deprecated.
Use getRequestProperty(String)
| |||||||||||
Set whether caches are used by default.
| |||||||||||
Sets whether this URLConnection allows input.
| |||||||||||
Sets whether this URLConnection allows output.
| |||||||||||
With permission from the security manager, this method sets the
map to be the MIME Table of this URL connection. | |||||||||||
Sets the header field
ifModifiedSince. | |||||||||||
Sets a timeout for reading to perform non-block.
| |||||||||||
Sets the value of the request header field
field to
newValue Only the current URL Connection is affected. | |||||||||||
Sets the flag indicating if this connection uses caches.
| |||||||||||
Returns the name of the class of the
URLConnection | |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
| |||||||||||
Creates a URLConnection pointing to the resource specified by the
url
Adds the given request property. Will not overwrite any existing properties associated with the given field name.
| field | the request property field name |
|---|---|
| newValue | the property value |
| IllegalStateException | - if connection already established |
|---|---|
| NullPointerException | - if field is null |
Establishes the connection to the resource specified by this
URL with this method, along with other
options that can only be set before this connection is made.
| IOException | If an error occurs while connecting |
|---|
Returns the value of allowUserInteraction which indicates
if this connection allows user interaction
Returns a timeout of connection by milliseconds
Returns the object pointed to by this URL. It first
attempts to get the content type from getContentType(),
which looks for the response header field "Content-Type". If none is
found, it will guess the content type from the filename extension. If
that fails, it will guess by inspecting the stream.
| types | The list of acceptable content types |
|---|
| IOException | If an error occurred obtaining the content. |
|---|
Returns the object pointed to by this URL. It first
attempts to get the content type from getContentType(),
which looks for the response header field "Content-Type". If none is
found, it will guess the content type from the filename extension. If
that fails, it will guess by inspecting the stream.
| IOException | if an IO error occurred |
|---|
Returns the Content encoding type of the response body, null if no such field is found in the header response.
Returns the length of the content or body in the response header in
bytes. Answer -1 if Content-Length cannot be found in the
response header.
Returns the type of the content. Returns null if there's
no such field.
Returns the date in milliseconds since epoch when this response header
was created, or 0 if the field Date is not found in the
header.
Returns whether this connection allow user interaction by default.
defaultAllowUserInteraction
This method is deprecated.Use getRequestProperty(String)
Returns the default value for the field specified by field,
null if there's no such field.
| field | the field to get the request property for |
|---|
Returns whether this connection use caches by default.
Returns whether this connection supports input.
Returns whether this connection supports output.
Returns the date in milliseconds since epoch when this response header
expires or 0 if the field Expires is not found in the
header.
Returns the MIME table of this URL connection.
Returns the value of the field at position pos.
Returns null if there are fewer than pos fields
in the response header.
| pos | the position of the field |
|---|
Returns the value of the field corresponding to the key
Returns null if there is no such field.
| key | the name of the header field |
|---|
Returns the date value in the form of milliseconds since epoch
corresponding to the field field. Returns
defaultValue if no such field can be found in the response
header.
| field | the field in question |
|---|---|
| defaultValue | the default value if no field is found |
Returns the integer value of the specified field. Returns default value
defaultValue if no such field exists.
| field | the field to return |
|---|---|
| defaultValue | to be returned if field> does not exist |
Returns the name of the field at position specified by posn,
null if there are fewer than posn fields.
| posn | the position to look for; the first field being 0 |
|---|
Provides an unmodifiable map of the connection header values. The map keys are the String header field names. Each map value is a List of the header field values associated with that key name.
Returns the value of ifModifiedSince of this connection in
milliseconds since epoch
Creates an InputStream for reading from this URL Connection. It throws UnknownServiceException by default. This method should be overridden by its subclasses
| IOException | If an InputStream could not be created |
|---|
Returns the value of the field Last-Modified in the
response header, 0 if no such field exists
Creates an OutputStream for writing to this URL Connection. It throws UnknownServiceException by default. This method should be overridden by subclasses.
| IOException | If an OutputStream could not be created |
|---|
Returns the permissions necessary to make the connection. Depending on the protocol, this can be any of the permission subclasses. The permission returned may also depend on the state of the connection, E.G In the case of HTTP, redirection can change the applicable permission if the host changed.
By default, this methods returns AllPermission.
Subclasses should override this and return the appropriate permission
object.
| IOException | if an IO exception occurs during the creation of the permission object. |
|---|
Returns a timeout of reading by milliseconds
Provides an unmodifiable map of the request properties. The map keys are Strings, the map values are each a List of Strings, with each request property name mapped to its corresponding property values.
Returns the value corresponding to the field in the request Header, null if no such field exists.
| field | the field to get the property for |
|---|
| IllegalStateException | - if connection already established |
|---|
Returns the URL of this connection
Returns whether this connection uses caches
Determines the MIME type of the file specified by the
string URL, using the filename extension. Any fragment
identifier is removed before processing.
| url | the MIME type of the file. |
|---|
Examines the bytes of the input stream and returns the MIME type, null if no content type can be deduced.
| is | the input stream for the URL |
|---|
| IOException | If an IO error occurs |
|---|
Sets the flag indicating whether this connection allows user interaction This can only be called prior to connection establishment.
| newValue | the value of the flag to be set |
|---|
| IllegalStateException | if this method attempts to change the flag after a connection has been established |
|---|
Sets a timeout for connection to perform non-block. Default is zero. Timeout of zero means infinite.
| timeout | timeout for connection in milliseconds. |
|---|
| IllegalArgumentException | if timeout is less than zero. |
|---|
Sets the current content handler factory to be
contentFactory. It can only do so with the permission of
the security manager. The ContentFactory can only be specified once
during the lifetime of an application.
| contentFactory | the factory |
|---|
| Error | if a ContentFactory has been created before SecurityException if the security manager does not allow this action |
|---|
Set whether user interaction is allowed by default. Existing URLConnections are unaffected.
| allows | allow user interaction |
|---|
This method is deprecated.Use getRequestProperty(String)
Sets the field in the default request header with the
value value
| field | the request header field to be set |
|---|---|
| value | the new value |
Set whether caches are used by default. Existing URLConnections are unaffected.
| newValue | the value of the flag to be set |
|---|
Sets whether this URLConnection allows input. It cannot be set after the connection is made.
| newValue | boolean |
|---|
| IllegalAccessError | Exception thrown when this method attempts to change the value after connected |
|---|
Sets whether this URLConnection allows output. It cannot be set after the connection is made.
| newValue | boolean |
|---|
| IllegalAccessError | Exception thrown when this method attempts to change the value after connected |
|---|
With permission from the security manager, this method sets the
map to be the MIME Table of this URL connection.
| map | the MIME table to be set. |
|---|
Sets the header field ifModifiedSince.
| newValue | number of milliseconds since epoch |
|---|
| IllegalStateException | if already connected. |
|---|
Sets a timeout for reading to perform non-block. Default is zero. Timeout of zero means infinite.
| timeout | timeout for reading in milliseconds. |
|---|
| IllegalArgumentException | if timeout is less than zero. |
|---|
Sets the value of the request header field field to
newValue Only the current URL Connection is affected. It
can only be called before the connection is made
| field | the field |
|---|---|
| newValue | the field's new value |
| IllegalStateException | - if connection already established |
|---|---|
| NullPointerException | - if field is null |
Sets the flag indicating if this connection uses caches. This value cannot be set after the connection is made.
| newValue | the value of the flag to be set |
|---|
| IllegalStateException | Exception thrown when this method attempts to change the value after connected |
|---|
Returns the name of the class of the URLConnection
URLConnection