◆ URLConnection()
| java.net.http.URLConnection.URLConnection |
( |
URL |
url | ) |
|
|
inlineprotected |
Constructs a URL connection to the specified URL. A connection to the object referenced by the URL is not created.
- Parameters
-
◆ addRequestProperty()
| void java.net.http.URLConnection.addRequestProperty |
( |
String |
key, |
|
|
String |
value |
|
) |
| |
|
inline |
Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.
- Parameters
-
| key | the keyword by which the request is known (e.g., "@code accept @endcode "). |
| value | the value associated with it. |
- Exceptions
-
| IllegalStateException | if already connected |
| NullPointerException | if key is null |
- See also
- #getRequestProperties(String)
- Since
- 1.4
◆ connect()
| abstract void java.net.http.URLConnection.connect |
( |
| ) |
throws IOException |
|
abstract |
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
If the
method is called when the connection has already been opened (indicated by the connected field having the value
), the call is ignored.
URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
- Exceptions
-
| IOException | if an I/O error occurs while opening the connection. |
◆ getAllowUserInteraction()
| boolean java.net.http.URLConnection.getAllowUserInteraction |
( |
| ) |
|
|
inline |
◆ getConnectTimeout()
| int java.net.http.URLConnection.getConnectTimeout |
( |
| ) |
|
|
inline |
Gets the configured connecting timeout.
- Returns
- the connecting timeout value in milliseconds.
◆ getContent()
| Object java.net.http.URLConnection.getContent |
( |
Class [] |
classes | ) |
throws IOException |
|
inline |
Retrieves the contents of this URL connection.
- Parameters
-
| classes | the array indicating the requested types |
- 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. The operator should be used to determine the specific kind of object returned.
- Exceptions
-
| IOException | if an I/O error occurs while getting the content. |
| UnknownServiceException | if the protocol does not support the content type. |
- See also
- #getContent()
-
java.net.ContentHandlerFactory::createContentHandler(String)
-
#getContent(Class[])
-
setContentHandlerFactory(java.net.ContentHandlerFactory)
◆ getContentEncoding()
| String java.net.http.URLConnection.getContentEncoding |
( |
| ) |
|
|
inline |
Returns the value of the
header field.
- Returns
- the content encoding of the resource that the URL references, or if not known.
- See also
- getHeaderField(String)
◆ getContentLength()
| int java.net.http.URLConnection.getContentLength |
( |
| ) |
|
|
inline |
Returns the value of the
header field.
- Returns
- the content length of the resource that this connection's URL references, or if the content length is not known.
◆ getContentType()
| String java.net.http.URLConnection.getContentType |
( |
| ) |
|
|
inline |
Returns the value of the
header field.
- Returns
- the content type of the resource that the URL references, or if not known.
- See also
- getHeaderField(String)
◆ getDate()
| long java.net.http.URLConnection.getDate |
( |
| ) |
|
|
inline |
Returns the value of the
header field.
- Returns
- the sending date of the resource that the URL references, or if not known. The value returned is the number of milliseconds since January 1, 1970 GMT.
- See also
- getHeaderField(String)
◆ getDefaultAllowUserInteraction()
| static boolean java.net.http.URLConnection.getDefaultAllowUserInteraction |
( |
| ) |
|
|
inlinestatic |
Returns the default value of the
field.
The default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.
- Returns
- the default value of the field.
- See also
- setDefaultAllowUserInteraction(boolean)
◆ getDefaultUseCaches()
| boolean java.net.http.URLConnection.getDefaultUseCaches |
( |
| ) |
|
|
inline |
Returns the default value of a
's
flag.
The default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.
- Returns
- the default value of a 's flag.
- See also
- setDefaultUseCaches(boolean)
◆ getDoInput()
| boolean java.net.http.URLConnection.getDoInput |
( |
| ) |
|
|
inline |
Returns the value of this
's
flag.
- Returns
- the value of this 's flag.
- See also
- setDoInput(boolean)
◆ getDoOutput()
| boolean java.net.http.URLConnection.getDoOutput |
( |
| ) |
|
|
inline |
◆ getExpiration()
| long java.net.http.URLConnection.getExpiration |
( |
| ) |
|
|
inline |
Returns the value of the
header field.
- 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.
- See also
- getHeaderField(String)
◆ getHeaderField() [1/2]
| String java.net.http.URLConnection.getHeaderField |
( |
String |
name | ) |
|
|
inline |
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 if there is no such field in the header.
◆ getHeaderField() [2/2]
| String java.net.http.URLConnection.getHeaderField |
( |
int |
idx | ) |
|
|
inline |
Returns the value for the
th header field. It returns
if there are fewer than
fields.
This method can be used in conjunction with the getHeaderFieldKey(int) method to iterate through all the headers in the message.
- Parameters
-
- Returns
- the value of the th header field or if there are fewer than fields
◆ getHeaderFieldDate()
| long java.net.http.URLConnection.getHeaderFieldDate |
( |
String |
name, |
|
|
long |
Default |
|
) |
| |
|
inline |
Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field.
This form of
exists because some connection types (e.g.,
) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.
- Parameters
-
| name | the name of the header field. |
| Default | a default value. |
- Returns
- the value of the field, parsed as a date. The value of the argument is returned if the field is missing or malformed.
◆ getHeaderFieldInt()
| int java.net.http.URLConnection.getHeaderFieldInt |
( |
String |
name, |
|
|
int |
Default |
|
) |
| |
|
inline |
Returns the value of the named field parsed as a number.
This form of
exists because some connection types (e.g.,
) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.
- Parameters
-
| name | the name of the header field. |
| Default | the default value. |
- Returns
- the value of the named field, parsed as an integer. The value is returned if the field is missing or malformed.
◆ getHeaderFieldKey()
| String java.net.http.URLConnection.getHeaderFieldKey |
( |
int |
n | ) |
|
|
inline |
Returns the key for the
th header field. It returns
if there are fewer than
fields.
- Parameters
-
- Returns
- the key for the th header field, or if there are fewer than fields.
◆ getIfModifiedSince()
| long java.net.http.URLConnection.getIfModifiedSince |
( |
| ) |
|
|
inline |
◆ getInputStream()
Returns an input stream that reads from this open connection.
- Returns
- an input stream that reads from this open connection.
- Exceptions
-
| IOException | if an I/O error occurs while creating the input stream. |
| UnknownServiceException | if the protocol does not support input. |
◆ getLastModified()
| long java.net.http.URLConnection.getLastModified |
( |
| ) |
|
|
inline |
Returns the value of the
header field. The result is the number of milliseconds since January 1, 1970 GMT.
- Returns
- the date the resource referenced by this was last modified, or 0 if not known.
- See also
- getHeaderField(String)
◆ getOutputStream()
Returns an output stream that writes to this connection.
- Returns
- an output stream that writes to this connection.
- Exceptions
-
| IOException | if an I/O error occurs while creating the output stream. |
| UnknownServiceException | if the protocol does not support output. |
◆ getRequestProperties()
| Map<String, List<String> > java.net.http.URLConnection.getRequestProperties |
( |
| ) |
|
|
inline |
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.
- Exceptions
-
| IllegalStateException | if already connected |
- Since
- 1.4
◆ getRequestProperty()
| String java.net.http.URLConnection.getRequestProperty |
( |
String |
key | ) |
|
|
inline |
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.
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- setRequestProperty(String, String)
◆ getURL()
| URL java.net.http.URLConnection.getURL |
( |
| ) |
|
|
inline |
Returns the value of this
's
field.
- Returns
- the value of this 's field.
- See also
- url
◆ getUseCaches()
| boolean java.net.http.URLConnection.getUseCaches |
( |
| ) |
|
|
inline |
◆ guessContentTypeFromName()
| static String java.net.http.URLConnection.guessContentTypeFromName |
( |
String |
fname | ) |
|
|
inlinestatic |
Tries to determine the content type of an object, based on the specified "file" component of a URL.
This is a convenience method that can be used by subclasses that override the getContentType() method.
- Parameters
-
- Returns
- a guess as to what the content type of the object is, based upon its file name.
◆ guessContentTypeFromStream()
Tries to determine the type of an input stream based on the characters at the beginning of the input stream. This method can be used by subclasses that override the getContentType() method.
Ideally, this routine would not be needed. But many
servers return the incorrect content type; in addition, there are many nonstandard extensions. Direct inspection of the bytes to determine the content type is often more accurate than believing the content type claimed by the
server.
- Parameters
-
| is | an input stream that supports marks. |
- Returns
- a guess at the content type, or if none can be determined.
- Exceptions
-
| IOException | if an I/O error occurs while reading the input stream. |
- See also
- java.io.InputStream::mark(int)
-
java.io.InputStream::markSupported()
File format used by digital cameras to store images. Exif Format can be read by any application supporting JPEG. Exif Spec can be found at: http://www.pima.net/standards/it10/PIMA15740/Exif_2-1.PDF
◆ setAllowUserInteraction()
| void java.net.http.URLConnection.setAllowUserInteraction |
( |
boolean |
allowuserinteraction | ) |
|
|
inline |
Set the value of the
field of this
.
- Parameters
-
| allowuserinteraction | the new value. |
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- getAllowUserInteraction()
◆ setContentHandlerFactory()
| static synchronized void java.net.http.URLConnection.setContentHandlerFactory |
( |
ContentHandlerFactory |
fac | ) |
|
|
inlinestatic |
Sets the
of an application. It can be called at most once by an application.
The
instance is used to construct a content handler from a content type
If there is a security manager, this method first calls the security manager's
method to ensure the operation is allowed. This could result in a SecurityException.
- Parameters
-
- Exceptions
-
| Error | if the factory has already been defined. |
| SecurityException | if a security manager exists and its method doesn't allow the operation. |
- See also
- java.net.ContentHandlerFactory
-
#getContent()
-
SecurityManager::checkSetFactory
◆ setDefaultAllowUserInteraction()
| static void java.net.http.URLConnection.setDefaultAllowUserInteraction |
( |
boolean |
defaultallowuserinteraction | ) |
|
|
inlinestatic |
Sets the default value of the
field for all future
objects to the specified value.
- Parameters
-
| defaultallowuserinteraction | the new value. |
- See also
- getDefaultAllowUserInteraction()
◆ setDefaultUseCaches()
| void java.net.http.URLConnection.setDefaultUseCaches |
( |
boolean |
defaultusecaches | ) |
|
|
inline |
Sets the default value of the
field to the specified value.
- Parameters
-
| defaultusecaches | the new value. |
- See also
- getDefaultUseCaches()
◆ setDoInput()
| void java.net.http.URLConnection.setDoInput |
( |
boolean |
doinput | ) |
|
|
inline |
Sets the value of the
field for this
to the specified value.
A URL connection can be used for input and/or output. Set the DoInput flag to true if you intend to use the URL connection for input, false if not. The default is true.
- Parameters
-
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- doInput
-
getDoInput()
◆ setDoOutput()
| void java.net.http.URLConnection.setDoOutput |
( |
boolean |
dooutput | ) |
|
|
inline |
Sets the value of the
field for this
to the specified value.
A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.
- Parameters
-
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- getDoOutput()
◆ setIfModifiedSince()
| void java.net.http.URLConnection.setIfModifiedSince |
( |
long |
ifmodifiedsince | ) |
|
|
inline |
Sets the value of the
field of this
to the specified value.
- Parameters
-
| ifmodifiedsince | the new value. |
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- getIfModifiedSince()
◆ setRequestProperty()
| void java.net.http.URLConnection.setRequestProperty |
( |
String |
key, |
|
|
String |
value |
|
) |
| |
|
inline |
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-separated 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., "@code accept @endcode "). |
| value | the value associated with it. |
- Exceptions
-
| IllegalStateException | if already connected |
| NullPointerException | if key is null |
- See also
- getRequestProperty(String)
◆ setUseCaches()
| void java.net.http.URLConnection.setUseCaches |
( |
boolean |
usecaches | ) |
|
|
inline |
Sets the value of the
field of this
to the specified value.
Some protocols do caching of documents. Occasionally, it is important to be able to "tunnel through" and ignore the caches (e.g., the "reload" button in a browser). If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can. If false, caches are to be ignored. The default value comes from DefaultUseCaches, which defaults to true.
- Parameters
-
| usecaches | a indicating whether or not to allow caching |
- Exceptions
-
| IllegalStateException | if already connected |
- See also
- getUseCaches()
◆ toString()
| String java.net.http.URLConnection.toString |
( |
| ) |
|
|
inline |
Returns a
representation of this URL connection.
- Returns
- a string representation of this .
◆ allowUserInteraction
| boolean java.net.http.URLConnection.allowUserInteraction = defaultAllowUserInteraction |
|
protected |
◆ connected
| boolean java.net.http.URLConnection.connected = false |
|
protected |
If
, this connection object has not created a communications link to the specified URL. If
, the communications link has been established.
◆ doInput
| boolean java.net.http.URLConnection.doInput = true |
|
protected |
This variable is set by the setDoInput(boolean) method. Its value is returned by the getDoInput() method.
A URL connection can be used for input and/or output. Setting the
flag to
indicates that the application intends to read data from the URL connection.
The default value of this field is
.
◆ doOutput
| boolean java.net.http.URLConnection.doOutput = false |
|
protected |
This variable is set by the setDoOutput(boolean) method. Its value is returned by the getDoOutput() method.
A URL connection can be used for input and/or output. Setting the
flag to
indicates that the application intends to write data to the URL connection.
The default value of this field is
.
◆ ifModifiedSince
| long java.net.http.URLConnection.ifModifiedSince = 0 |
|
protected |
Some protocols support skipping the fetching of the object unless the object has been modified more recently than a certain time.
A nonzero value gives a time as the number of milliseconds since January 1, 1970, GMT. The object is fetched only if it has been modified more recently than that time.
This variable is set by the setIfModifiedSince(long) method. Its value is returned by the getIfModifiedSince() method.
The default value of this field is
, indicating that the fetching must always occur.
◆ requestProperties
| HashMap<String, String> java.net.http.URLConnection.requestProperties |
|
protected |
◆ url
| URL java.net.http.URLConnection.url |
|
protected |
The URL represents the remote object on the World Wide Web to which this connection is opened.
The value of this field can be accessed by the getURL() method.
The default value of this variable is the value of the URL argument in the
constructor.
◆ useCaches
| boolean java.net.http.URLConnection.useCaches = defaultUseCaches |
|
protected |
If
, the protocol is allowed to use caching whenever it can. If
, the protocol must always try to get a fresh copy of the object.
This field is set by the setUseCaches(boolean) method. Its value is returned by the getUseCaches() method.
Its default value is the value given in the last invocation of the setDefaultUseCaches(boolean) method.
The documentation for this class was generated from the following file:
- src/java/net/http/URLConnection.java