Java Reference
In-Depth Information
load a fixed set of files at launch time and then only serve those out of memory. This
might be useful for a server that processes many different SOAP requests, all of which
adhere to a few common schemas that can be stored in the cache. The abstract
ResponseCache
class is flexible enough to support all of these and other usage patterns.
Configuring the Connection
The
URLConnection
class has seven protected instance fields that define exactly how the
client makes the request to the server. These are:
protected
URL
url
;
protected
boolean
doInput
=
true
;
protected
boolean
doOutput
=
false
;
protected
boolean
allowUserInteraction
=
defaultAllowUserInteraction
;
protected
boolean
useCaches
=
defaultUseCaches
;
protected
long
ifModifiedSince
=
0
;
protected
boolean
connected
=
false
;
For instance, if
doOutput
is
true
, you'll be able to write data to the server over this
URLConnection
as well as read data from it. If
useCaches
is
false
, the connection by‐
passes any local caching and downloads the file from the server afresh.
Because these fields are all protected, their values are accessed and modified via obvi‐
ously named setter and getter methods:
public
URL
getURL
()
public
void
setDoInput
(
boolean
doInput
)
public
boolean
getDoInput
()
public
void
setDoOutput
(
boolean
doOutput
)
public
boolean
getDoOutput
()
public
void
setAllowUserInteraction
(
boolean
allowUserInteraction
)
public
boolean
getAllowUserInteraction
()
public
void
setUseCaches
(
boolean
useCaches
)
public
boolean
getUseCaches
()
public
void
setIfModifiedSince
(
long
ifModifiedSince
)
public
long
getIfModifiedSince
()
You can modify these fields only before the
URLConnection
is connected (before you
try to read content or headers from the connection). Most of the methods that set fields
throw an
IllegalStateException
if they are called while the connection is open. In
general, you can set the properties of a
URLConnection
object only before the connection
is opened.
There are also some getter and setter methods that define the default behavior for all
instances of
URLConnection
. These are:
public
boolean
getDefaultUseCaches
()
public
void
setDefaultUseCaches
(
boolean
defaultUseCaches
)
public
static
void
setDefaultAllowUserInteraction
(
boolean
defaultAllowUserInteraction
)