|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.net.URLConnection
public abstract class URLConnection
Concrete implementations of the abstract URLConnection class provide
a communication link to a URL for exchanging data with a specific protocol
type. A URLConnection can only be set up after the instantiation but
before connecting to the remote resource.
| Nested Class Summary | |
|---|---|
(package private) static class |
URLConnection.DefaultContentHandler
|
| Field Summary | |
|---|---|
protected boolean |
allowUserInteraction
Specifies whether this URLConnection allows user interaction as
it is needed for authentication purposes. |
protected boolean |
connected
Specifies whether this URLConnection is already connected to the
remote resource. |
(package private) static Hashtable<String,Object> |
contentHandlers
Cache for storing content handler |
(package private) ContentHandler |
defaultHandler
|
protected boolean |
doInput
Specifies whether this URLConnection allows receiving data. |
protected boolean |
doOutput
Specifies whether this URLConnection allows sending data. |
protected long |
ifModifiedSince
The data must be modified more recently than this time in milliseconds since January 1, 1970, GMT to be transmitted. |
protected URL |
url
The URL which represents the remote target of this URLConnection. |
protected boolean |
useCaches
Specifies whether the using of caches is enabled or the data has to be recent for every request. |
| Constructor Summary | |
|---|---|
protected |
URLConnection(URL url)
Creates a new URLConnection instance pointing to the resource
specified by the given URL. |
| Method Summary | |
|---|---|
void |
addRequestProperty(String field,
String newValue)
Adds the given property to the request header. |
abstract void |
connect()
Establishes the connection to the earlier configured resource. |
boolean |
getAllowUserInteraction()
Gets the option value which indicates whether user interaction is allowed on this URLConnection. |
int |
getConnectTimeout()
Gets the configured connecting timeout. |
Object |
getContent()
Gets an object representing the content of the resource this URLConnection is connected to. |
Object |
getContent(Class[] types)
Gets an object representing the content of the resource this URLConnection is connected to. |
String |
getContentEncoding()
Gets the content encoding type specified by the response header field content-encoding or null if this field is not set. |
int |
getContentLength()
Gets the content length in bytes specified by the response header field content-length or -1 if this field is not set. |
String |
getContentType()
Gets the MIME-type of the content specified by the response header field content-type or null if type is unknown. |
long |
getDate()
Gets the timestamp when this response has been sent as a date in milliseconds since January 1, 1970 GMT or 0 if this timestamp is
unknown. |
static boolean |
getDefaultAllowUserInteraction()
Gets the default setting whether this connection allows user interaction. |
static String |
getDefaultRequestProperty(String field)
Deprecated. Use getRequestProperty(java.lang.String) |
boolean |
getDefaultUseCaches()
Gets the default setting whether this connection allows using caches. |
boolean |
getDoInput()
Gets the value of the option doInput which specifies whether this
connection allows to receive data. |
boolean |
getDoOutput()
Gets the value of the option doOutput which specifies whether
this connection allows to send data. |
long |
getExpiration()
Gets the timestamp when this response will be expired in milliseconds since January 1, 1970 GMT or 0 if this timestamp is unknown. |
static FileNameMap |
getFileNameMap()
Gets the table which is used by all URLConnection instances to
determine the MIME-type according to a file extension. |
String |
getHeaderField(int pos)
Gets the header value at the field position pos or null
if the header has fewer than pos fields. |
String |
getHeaderField(String key)
Gets the value of the header field specified by key or null if there is no field with this name. |
long |
getHeaderFieldDate(String field,
long defaultValue)
Gets the specified header value as a date in milliseconds since January 1, 1970 GMT. |
int |
getHeaderFieldInt(String field,
int defaultValue)
Gets the specified header value as a number. |
String |
getHeaderFieldKey(int posn)
Gets the name of the header field at the given position posn or
null if there are fewer than posn fields. |
Map<String,List<String>> |
getHeaderFields()
Gets an unchangeable map of the response-header fields and values. |
long |
getIfModifiedSince()
Gets the point of time since when the data must be modified to be transmitted. |
InputStream |
getInputStream()
Gets an InputStream for reading data from the resource pointed by
this URLConnection. |
long |
getLastModified()
Gets the value of the response header field last-modified or
0 if this value is not set. |
OutputStream |
getOutputStream()
Gets an OutputStream for writing data to this URLConnection. |
Permission |
getPermission()
Gets a Permission object representing all needed permissions to
open this connection. |
int |
getReadTimeout()
Gets the configured timeout for reading from the input stream of an established connection to the resource. |
Map<String,List<String>> |
getRequestProperties()
Gets an unchangeable map of general request properties used by this connection. |
String |
getRequestProperty(String field)
Gets the value of the request header property specified by {code field} or null if there is no field with this name. |
URL |
getURL()
Gets the URL represented by this URLConnection. |
boolean |
getUseCaches()
Gets the value of the flag which specifies whether this URLConnection allows to use caches. |
static String |
guessContentTypeFromName(String url)
Determines the MIME-type of the given resource url by resolving
the filename extension with the internal FileNameMap. |
static String |
guessContentTypeFromStream(InputStream is)
Determines the MIME-type of the resource represented by the input stream is by reading its first few characters. |
void |
setAllowUserInteraction(boolean newValue)
Sets the flag indicating whether this connection allows user interaction or not. |
void |
setConnectTimeout(int timeout)
Sets the timeout value in milliseconds for establishing the connection to the resource pointed by this URLConnection instance. |
static void |
setContentHandlerFactory(ContentHandlerFactory contentFactory)
Sets the internally used content handler factory. |
static void |
setDefaultAllowUserInteraction(boolean allows)
Sets the default value for the flag indicating whether this connection allows user interaction or not. |
static void |
setDefaultRequestProperty(String field,
String value)
Deprecated. Use setRequestProperty(java.lang.String, java.lang.String) of an existing URLConnection instance. |
void |
setDefaultUseCaches(boolean newValue)
Sets the default value for the flag indicating whether this connection allows to use caches. |
void |
setDoInput(boolean newValue)
Sets the flag indicating whether this URLConnection allows input. |
void |
setDoOutput(boolean newValue)
Sets the flag indicating whether this URLConnection allows
output. |
static void |
setFileNameMap(FileNameMap map)
Sets the internal map which is used by all URLConnection
instances to determine the MIME-type according to a filename extension. |
void |
setIfModifiedSince(long newValue)
Sets the point of time since when the data must be modified to be transmitted. |
void |
setReadTimeout(int timeout)
Sets the timeout value in milliseconds for reading from the input stream of an established connection to the resource. |
void |
setRequestProperty(String field,
String newValue)
Sets the value of the specified request header field. |
void |
setUseCaches(boolean newValue)
Sets the flag indicating whether this connection allows to use caches or not. |
String |
toString()
Returns the string representation containing the name of this class and the URL. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected URL url
URLConnection.
ContentHandler defaultHandler
protected long ifModifiedSince
protected boolean useCaches
protected boolean connected
URLConnection is already connected to the
remote resource. If this field is set to true the flags for
setting up the connection are not changeable anymore.
protected boolean doOutput
URLConnection allows sending data.
protected boolean doInput
URLConnection allows receiving data.
protected boolean allowUserInteraction
URLConnection allows user interaction as
it is needed for authentication purposes.
static Hashtable<String,Object> contentHandlers
| Constructor Detail |
|---|
protected URLConnection(URL url)
URLConnection instance pointing to the resource
specified by the given URL.
url - the URL which represents the resource this URLConnection will point to.| Method Detail |
|---|
public abstract void connect()
throws IOException
IOException - if an error occurs while connecting to the resource.public boolean getAllowUserInteraction()
URLConnection.
allowUserInteraction.allowUserInteraction
public Object getContent()
throws IOException
URLConnection is connected to. First, it attempts to get the content
type from the method getContentType() which looks at the response
header field "Content-Type". If none is found it will guess the content
type from the filename extension. If that fails the stream itself will be
used to guess the content type.
IOException - if an error occurs obtaining the content.
public Object getContent(Class[] types)
throws IOException
URLConnection is connected to. First, it attempts to get the content
type from the method getContentType() which looks at the response
header field "Content-Type". If none is found it will guess the content
type from the filename extension. If that fails the stream itself will be
used to guess the content type. The content type must match with one of
the list types.
types - the list of acceptable content types.
null if the content
type does not match with one of the specified types.
IOException - if an error occurs obtaining the content.public String getContentEncoding()
content-encoding or null if this field is not set.
content-encoding.public int getContentLength()
content-length or -1 if this field is not set.
content-length.public String getContentType()
content-type or null if type is unknown.
content-type.public long getDate()
0 if this timestamp is
unknown.
public static boolean getDefaultAllowUserInteraction()
defaultAllowUserInteraction.allowUserInteraction@Deprecated public static String getDefaultRequestProperty(String field)
getRequestProperty(java.lang.String)
field or null if the field could not be found. The current implementation of this
method returns always null.
field - the request field whose default value shall be returned.
public boolean getDefaultUseCaches()
defaultUseCaches.useCachespublic boolean getDoInput()
doInput which specifies whether this
connection allows to receive data.
true if this connection allows input, false
otherwise.doInputpublic boolean getDoOutput()
doOutput which specifies whether
this connection allows to send data.
true if this connection allows output, false
otherwise.doOutputpublic long getExpiration()
0 if this timestamp is unknown.
expires.public static FileNameMap getFileNameMap()
URLConnection instances to
determine the MIME-type according to a file extension.
public String getHeaderField(int pos)
pos or null
if the header has fewer than pos fields. The current
implementation of this method returns always null.
pos - the field position of the response header.
pos.public Map<String,List<String>> getHeaderFields()
public Map<String,List<String>> getRequestProperties()
public void addRequestProperty(String field,
String newValue)
field - the request property field name to add.newValue - the value of the property which is to add.
IllegalStateException - if the connection has been already established.
NullPointerException - if the property name is null.public String getHeaderField(String key)
key or null if there is no field with this name. The current implementation of
this method returns always null.
key - the name of the header field.
public long getHeaderFieldDate(String field,
long defaultValue)
defaultValue if no such header field
could be found.
field - the header field name whose value is needed.defaultValue - the default value if no field has been found.
public int getHeaderFieldInt(String field,
int defaultValue)
defaultValue if no such header field could be found or the value could
not be parsed as an Integer.
field - the header field name whose value is needed.defaultValue - the default value if no field has been found.
public String getHeaderFieldKey(int posn)
posn or
null if there are fewer than posn fields. The current
implementation of this method returns always null.
posn - the position of the header field which has to be returned.
public long getIfModifiedSince()
ifModifiedSince
public InputStream getInputStream()
throws IOException
InputStream for reading data from the resource pointed by
this URLConnection. It throws an UnknownServiceException by
default. This method must be overridden by its subclasses.
IOException - if no InputStream could be created.public long getLastModified()
last-modified or
0 if this value is not set.
last-modified header field.
public OutputStream getOutputStream()
throws IOException
OutputStream for writing data to this URLConnection. It throws an UnknownServiceException by default.
This method must be overridden by its subclasses.
IOException - if no OutputStream could be created.
public Permission getPermission()
throws IOException
Permission object representing all needed permissions to
open this connection. The returned permission object depends on the state
of the connection and will be null if no permissions are
necessary. By default, this method returns AllPermission.
Subclasses should overwrite this method to return an appropriate
permission object.
IOException - if an I/O error occurs while creating the permission object.public String getRequestProperty(String field)
null if there is no field with this name. The current
implementation of this method returns always null.
field - the name of the request header property.
IllegalStateException - if the connection has been already established.public URL getURL()
URLConnection.
public boolean getUseCaches()
URLConnection allows to use caches.
true if using caches is allowed, false otherwise.public static String guessContentTypeFromName(String url)
url by resolving
the filename extension with the internal FileNameMap. Any fragment
identifier is removed before processing.
url - the URL with the filename to get the MIME type.
null if the type could not be
determined.
public static String guessContentTypeFromStream(InputStream is)
throws IOException
is by reading its first few characters.
is - the resource representing input stream to determine the
content type.
null if the type could not be
determined.
IOException - if an I/O error occurs while reading from the input stream.public void setAllowUserInteraction(boolean newValue)
newValue - the value of the flag to be set.
IllegalStateException - if this method attempts to change the flag after the
connection has been established.allowUserInteractionpublic static void setContentHandlerFactory(ContentHandlerFactory contentFactory)
contentFactory - the content factory to be set.
Error - if the security manager does not allow to set the content
factory or it has been already set earlier ago.public static void setDefaultAllowUserInteraction(boolean allows)
URLConnections are
unaffected.
allows - the default value of the flag to be used for new connections.defaultAllowUserInteraction,
allowUserInteraction
@Deprecated
public static void setDefaultRequestProperty(String field,
String value)
setRequestProperty(java.lang.String, java.lang.String) of an existing URLConnection instance.
field - the request header field to be set.value - the default value to be used.public void setDefaultUseCaches(boolean newValue)
URLConnections are unaffected.
newValue - the default value of the flag to be used for new connections.defaultUseCaches,
useCachespublic void setDoInput(boolean newValue)
URLConnection allows input.
It cannot be set after the connection is established.
newValue - the new value for the flag to be set.
IllegalAccessError - if this method attempts to change the value after the
connection has been already established.doInputpublic void setDoOutput(boolean newValue)
URLConnection allows
output. It cannot be set after the connection is established.
newValue - the new value for the flag to be set.
IllegalAccessError - if this method attempts to change the value after the
connection has been already established.doOutputpublic static void setFileNameMap(FileNameMap map)
URLConnection
instances to determine the MIME-type according to a filename extension.
map - the MIME table to be set.public void setIfModifiedSince(long newValue)
0.
newValue - the time in milliseconds since January 1, 1970 GMT.
IllegalStateException - if this URLConnection has already been connected.ifModifiedSince
public void setRequestProperty(String field,
String newValue)
URLConnection instance. This method can
only be called before the connection is established.
field - the request header field to be set.newValue - the new value of the specified property.
IllegalStateException - if the connection has been already established.
NullPointerException - if the parameter field is null.public void setUseCaches(boolean newValue)
newValue - the value of the flag to be set.
IllegalStateException - if this method attempts to change the flag after the
connection has been established.useCachespublic void setConnectTimeout(int timeout)
URLConnection instance. A SocketTimeoutException is thrown if the connection could not be
established in this time. Default is 0 which stands for an
infinite timeout.
timeout - the connecting timeout in milliseconds.
IllegalArgumentException - if the parameter timeout is less than zero.public int getConnectTimeout()
public void setReadTimeout(int timeout)
SocketTimeoutException is thrown if the connection could not be
established in this time. Default is 0 which stands for an
infinite timeout.
timeout - the reading timeout in milliseconds.
IllegalArgumentException - if the parameter timeout is less than zero.public int getReadTimeout()
public String toString()
toString in class ObjectURLConnection instance.
|
Build 1.1_r1 (from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||