DthingApi
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
java.net.http.URLConnection Class Referenceabstract
Inheritance diagram for java.net.http.URLConnection:
java.net.http.HttpURLConnection

Public Member Functions

abstract void connect () throws IOException
 
URL getURL ()
 
int getContentLength ()
 
String getContentType ()
 
String getContentEncoding ()
 
long getExpiration ()
 
long getDate ()
 
long getLastModified ()
 
void setConnectTimeout (int timeout)
 
int getConnectTimeout ()
 
void setReadTimeout (int timeout)
 
int getReadTimeout ()
 
String getHeaderField (String name)
 
String getHeaderField (int idx)
 
int getHeaderFieldInt (String name, int Default)
 
long getHeaderFieldDate (String name, long Default)
 
String getHeaderFieldKey (int n)
 
Object getContent () throws IOException
 
Object getContent (Class[] classes) throws IOException
 
abstract InputStream getInputStream () throws IOException
 
abstract OutputStream getOutputStream () throws IOException
 
String toString ()
 
void setDoInput (boolean doinput)
 
boolean getDoInput ()
 
void setDoOutput (boolean dooutput)
 
boolean getDoOutput ()
 
void setAllowUserInteraction (boolean allowuserinteraction)
 
boolean getAllowUserInteraction ()
 
void setUseCaches (boolean usecaches)
 
boolean getUseCaches ()
 
void setIfModifiedSince (long ifmodifiedsince)
 
long getIfModifiedSince ()
 
boolean getDefaultUseCaches ()
 
void setDefaultUseCaches (boolean defaultusecaches)
 
void setRequestProperty (String key, String value)
 
void addRequestProperty (String key, String value)
 
String getRequestProperty (String key)
 
Map< String, List< String > > getRequestProperties ()
 

Static Public Member Functions

static void setDefaultAllowUserInteraction (boolean defaultallowuserinteraction)
 
static boolean getDefaultAllowUserInteraction ()
 
static synchronized void setContentHandlerFactory (ContentHandlerFactory fac)
 
static String guessContentTypeFromName (String fname)
 
static String guessContentTypeFromStream (InputStream is) throws IOException
 

Protected Member Functions

 URLConnection (URL url)
 
int getDefaultPort ()
 

Protected Attributes

URL url
 
boolean doInput = true
 
boolean doOutput = false
 
boolean allowUserInteraction = defaultAllowUserInteraction
 
boolean useCaches = defaultUseCaches
 
long ifModifiedSince = 0
 
boolean connected = false
 
int connectTimeout = 0
 
int readTimeout = 0
 
HashMap< String, String > requestProperties
 
LinkedHashMap< String, String > responseProperties
 

Constructor & Destructor Documentation

◆ 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
urlthe specified URL.

Member Function Documentation

◆ 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
keythe keyword by which the request is known (e.g., "@code accept @endcode ").
valuethe value associated with it.
Exceptions
IllegalStateExceptionif already connected
NullPointerExceptionif 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

true

), 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
IOExceptionif an I/O error occurs while opening the connection.

◆ getAllowUserInteraction()

boolean java.net.http.URLConnection.getAllowUserInteraction ( )
inline

Returns the value of the

field for this object.

Returns
the value of the field for this object.
See also
setAllowUserInteraction(boolean)

◆ 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
classesthe
Class
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
instanceof
operator should be used to determine the specific kind of object returned.
Exceptions
IOExceptionif an I/O error occurs while getting the content.
UnknownServiceExceptionif 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

content-encoding

header field.

Returns
the content encoding of the resource that the URL references, or
null
if not known.
See also
getHeaderField(String)

◆ getContentLength()

int java.net.http.URLConnection.getContentLength ( )
inline

Returns the value of the

content-length

header field.

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

◆ getContentType()

String java.net.http.URLConnection.getContentType ( )
inline

Returns the value of the

content-type

header field.

Returns
the content type of the resource that the URL references, or
null
if not known.
See also
getHeaderField(String)

◆ getDate()

long java.net.http.URLConnection.getDate ( )
inline

Returns the value of the

date

header field.

Returns
the sending date of the resource that the URL references, or
0
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

Returns the value of this

's

flag.

Returns
the value of this 's flag.
See also
setDoOutput(boolean)

◆ getExpiration()

long java.net.http.URLConnection.getExpiration ( )
inline

Returns the value of the

expires

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
namethe name of a header field.
Returns
the value of the named header field, or
null
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

n

th header field. It returns

null

if there are fewer than

n+1

fields.

This method can be used in conjunction with the getHeaderFieldKey(int) method to iterate through all the headers in the message.

Parameters
idxan index, where n>=0
Returns
the value of the
n
th header field or
null
if there are fewer than
n+1
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.,

http-ng

) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

Parameters
namethe name of the header field.
Defaulta default value.
Returns
the value of the field, parsed as a date. The value of the
Default
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.,

http-ng

) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

Parameters
namethe name of the header field.
Defaultthe default value.
Returns
the value of the named field, parsed as an integer. The
Default
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

n

th header field. It returns

null

if there are fewer than

n+1

fields.

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

◆ getIfModifiedSince()

long java.net.http.URLConnection.getIfModifiedSince ( )
inline

Returns the value of this object's

field.

Returns
the value of this object's field.
See also
setIfModifiedSince(long)

◆ getInputStream()

abstract InputStream java.net.http.URLConnection.getInputStream ( ) throws IOException
abstract

Returns an input stream that reads from this open connection.

Returns
an input stream that reads from this open connection.
Exceptions
IOExceptionif an I/O error occurs while creating the input stream.
UnknownServiceExceptionif the protocol does not support input.

◆ getLastModified()

long java.net.http.URLConnection.getLastModified ( )
inline

Returns the value of the

last-modified

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()

abstract OutputStream java.net.http.URLConnection.getOutputStream ( ) throws IOException
abstract

Returns an output stream that writes to this connection.

Returns
an output stream that writes to this connection.
Exceptions
IOExceptionif an I/O error occurs while creating the output stream.
UnknownServiceExceptionif 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
IllegalStateExceptionif 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
keythe 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
IllegalStateExceptionif already connected
See also
setRequestProperty(String, String)

◆ getURL()

URL java.net.http.URLConnection.getURL ( )
inline

Returns the value of this

's

URL

field.

Returns
the value of this 's
URL
field.
See also
url

◆ getUseCaches()

boolean java.net.http.URLConnection.getUseCaches ( )
inline

Returns the value of this

's

field.

Returns
the value of this 's field.
See also
setUseCaches(boolean)

◆ 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
fnamea filename.
Returns
a guess as to what the content type of the object is, based upon its file name.

◆ guessContentTypeFromStream()

static String java.net.http.URLConnection.guessContentTypeFromStream ( InputStream  is) throws IOException
inlinestatic

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

http

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

http

server.

Parameters
isan input stream that supports marks.
Returns
a guess at the content type, or
null
if none can be determined.
Exceptions
IOExceptionif 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
allowuserinteractionthe new value.
Exceptions
IllegalStateExceptionif already connected
See also
getAllowUserInteraction()

◆ setContentHandlerFactory()

static synchronized void java.net.http.URLConnection.setContentHandlerFactory ( ContentHandlerFactory  fac)
inlinestatic

Sets the

ContentHandlerFactory

of an application. It can be called at most once by an application.

The

ContentHandlerFactory

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

checkSetFactory

method to ensure the operation is allowed. This could result in a SecurityException.

Parameters
facthe desired factory.
Exceptions
Errorif the factory has already been defined.
SecurityExceptionif a security manager exists and its
checkSetFactory
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
defaultallowuserinteractionthe 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
defaultusecachesthe 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
doinputthe new value.
Exceptions
IllegalStateExceptionif 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
dooutputthe new value.
Exceptions
IllegalStateExceptionif 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
ifmodifiedsincethe new value.
Exceptions
IllegalStateExceptionif 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
keythe keyword by which the request is known (e.g., "@code accept @endcode ").
valuethe value associated with it.
Exceptions
IllegalStateExceptionif already connected
NullPointerExceptionif 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
usecachesa
boolean
indicating whether or not to allow caching
Exceptions
IllegalStateExceptionif already connected
See also
getUseCaches()

◆ toString()

String java.net.http.URLConnection.toString ( )
inline

Returns a

String

representation of this URL connection.

Returns
a string representation of this .

Member Data Documentation

◆ allowUserInteraction

boolean java.net.http.URLConnection.allowUserInteraction = defaultAllowUserInteraction
protected

If

true

, this

URL

is being examined in a context in which it makes sense to allow user interactions such as popping up an authentication dialog. If

false

, then no user interaction is allowed.

The value of this field can be set by the setAllowUserInteraction(boolean) method. Its value is returned by the getAllowUserInteraction() method. Its default value is the value of the argument in the last invocation of the setDefaultAllowUserInteraction(boolean) method.

◆ connected

boolean java.net.http.URLConnection.connected = false
protected

If

false

, this connection object has not created a communications link to the specified URL. If

true

, 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

true

indicates that the application intends to read data from the URL connection.

The default value of this field is

true

.

◆ 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

true

indicates that the application intends to write data to the URL connection.

The default value of this field is

false

.

◆ 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

0

, indicating that the fetching must always occur.

◆ requestProperties

HashMap<String, String> java.net.http.URLConnection.requestProperties
protected
Since
1.2.2

◆ 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

true

, the protocol is allowed to use caching whenever it can. If

false

, 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: