java.lang.Object | +--java.net.URLConnection
boolean | allowUserInteraction This variable determines whether or not interaction is allowed with the user. |
boolean | connected Indicates whether or not a connection has been established to the destination specified in the URL |
boolean | doInput Indicates whether or not input can be read from this URL |
boolean | doOutput Indicates whether or not output can be sent to this URL |
long | ifModifiedSince If this value is non-zero, then the connection will only attempt to fetch the document pointed to by the URL if the document has been modified more recently than the date set in this variable. |
java.net.URL | url This is the URL associated with this connection |
boolean | useCaches If this flag is set, the protocol is allowed to cache data whenever it can (caching is not guaranteed). |
URLConnection(java.net.URL url) This constructs a URLConnection from a URL object |
void | connect() Establishes the actual connection to the URL associated with this connection object |
boolean | getAllowUserInteraction() Returns a boolean flag indicating whether or not user interaction is allowed for this connection. |
java.lang.Object | getContent() This method returns the content of the document pointed to by the URL as an Object. |
java.lang.String | getContentEncoding() Returns the value of the content-encoding field or null if it is not known or not present. |
int | getContentLength() Returns the value of the content-length header field or -1 if the value is not known or not present. |
java.lang.String | getContentType() Returns the the content-type of the data pointed to by the URL. |
long | getDate() Returns the date of the document pointed to by the URL as reported in the date field of the header or 0 if the value is not present or not known. |
static boolean | getDefaultAllowUserInteraction() Returns the default flag for whether or not interaction with a user is allowed. |
static java.lang.String | getDefaultRequestProperty(java.lang.String key) Returns the default value of a request property. |
boolean | getDefaultUseCaches() Returns the default value used to determine whether or not caching of documents will be done when possible. |
boolean | getDoInput() Returns the value of a flag indicating whether or not input is going to be done for this connection. |
boolean | getDoOutput() Returns a boolean flag indicating whether or not output will be done on this connection. |
long | getExpiration() Returns the value of the expires header or 0 if not known or present. |
static java.net.FileNameMap | getFileNameMap() This method returns the |
java.lang.String | getHeaderField(int index) Return a String representing the header value at the specified index. |
java.lang.String | getHeaderField(java.lang.String name) Returns a String representing the value of the header field having the named key. |
long | getHeaderFieldDate(java.lang.String key, long def) Returns the value of the named header field as a date. |
int | getHeaderFieldInt(java.lang.String key, int def) Returns the value of the named header field as an int. |
java.lang.String | getHeaderFieldKey(int index) Returns a String representing the header key at the specified index. |
long | getIfModifiedSince() Returns the ifModified since instance variable. |
java.io.InputStream | getInputStream() Returns an InputStream for this connection. |
long | getLastModified() Returns the value of the last-modified header field or 0 if not known known or not present. |
java.io.OutputStream | getOutputStream() Returns an OutputStream for this connection. |
java.security.Permission | getPermission() This method returns a |
java.util.Map | getRequestProperties() Returns an unmodifiable Map containing the request properties. |
java.lang.String | getRequestProperty(java.lang.String key) Returns the value of the named request property. |
java.net.URL | getURL() Returns the URL object associated with this connection |
boolean | getUseCaches() Returns a boolean flag indicating whether or not caching will be used (if possible) to store data downloaded via the connection. |
static java.lang.String | guessContentTypeFromName(java.lang.String filename) Returns the MIME type of a file based on the name of the file. |
static java.lang.String | guessContentTypeFromStream(java.io.InputStream is) Returns the MIME type of a stream based on the first few characters at the beginning of the stream. |
void | setAllowUserInteraction(boolean allow) Sets a boolean flag indicating whether or not user interaction is allowed for this connection. |
static synchronized void | setContentHandlerFactory(java.net.ContentHandlerFactory fac) Set's the ContentHandlerFactory for an application. |
static synchronized void | setDefaultAllowUserInteraction(boolean allow) Sets the default flag for whether or not interaction with a user is allowed. |
static synchronized void | setDefaultRequestProperty(java.lang.String key, java.lang.String value) Sets the default value of a request property. |
synchronized void | setDefaultUseCaches(boolean use) Sets the default value used to determine whether or not caching of documents will be done when possible. |
void | setDoInput(boolean input) Returns the value of a flag indicating whether or not input is going to be done for this connection. |
void | setDoOutput(boolean output) Returns a boolean flag indicating whether or not output will be done on this connection. |
static void | setFileNameMap(java.net.FileNameMap fileNameMap) This method set the |
void | setIfModifiedSince(long modified_since) Sets the ifModified since instance variable. |
void | setRequestProperty(java.lang.String key, java.lang.String value) Sets the value of the named request property |
void | setUseCaches(boolean use_caches) Sets a boolean flag indicating whether or not caching will be used (if possible) to store data downloaded via the connection. |
java.lang.String | toString() The methods prints the value of this object as a String by calling the toString() method of its associated URL. |
protected boolean allowUserInteraction
protected boolean connected
protected boolean doInput
protected boolean doOutput
protected long ifModifiedSince
protected URL url
protected boolean useCaches
This field is set by the setUseCaches method and returned by the getUseCaches method. Its default value is that determined by the last invocation of setDefaultUseCaches
protected URLConnection(java.net.URL url)
url
- The URL for this connectionpublic void connect()
public boolean getAllowUserInteraction()
public Object getContent()
This class first determines the MIME type of the content, then creates
a ContentHandler object to process the input. If the ContentHandlerFactory
is set, then that object is called to load a content handler, otherwise
a class called gnu.java.net.content.
IOException
- If an error occurs.public String getContentEncoding()
public int getContentLength()
public String getContentType()
public long getDate()
public static boolean getDefaultAllowUserInteraction()
public static String getDefaultRequestProperty(java.lang.String key)
key
- The request property to return the default value ofpublic boolean getDefaultUseCaches()
public boolean getDoInput()
public boolean getDoOutput()
public long getExpiration()
public static FileNameMap getFileNameMap()
FileNameMap
object being used
to decode MIME types by file extension.
FileNameMap
.public String getHeaderField(int index)
index
- The index into the header field list to retrieve the value forpublic String getHeaderField(java.lang.String name)
name
- key of the header fieldpublic long getHeaderFieldDate(java.lang.String key, long def)
key
- The header field key to lookupdef
- The default value if the header field is not found or can't be convertedpublic int getHeaderFieldInt(java.lang.String key, int def)
key
- The header field key to lookupdef
- The defaule value if the header field is not found or can't be parsedpublic String getHeaderFieldKey(int index)
index
- The index into the header field list to retrieve the key for.public long getIfModifiedSince()
public InputStream getInputStream()
IOException
- If an error occurspublic long getLastModified()
public OutputStream getOutputStream()
IOException
- If an error occurspublic Permission getPermission()
Permission
object representing the
permissions required to access this URL. This method returns
java.security.AllPermission
by default. Subclasses should
override it to return a more specific permission. For example, an
HTTP URL should return an instance of SocketPermission
for the appropriate host and port.
Note that because of items such as HTTP redirects, the permission object returned might be different before and after connecting.
IOException
- If an error occurspublic Map getRequestProperties()
public String getRequestProperty(java.lang.String key)
key
- The name of the propertypublic URL getURL()
public boolean getUseCaches()
public static String guessContentTypeFromName(java.lang.String filename)
filename
- The filename to determine the MIME type forpublic static String guessContentTypeFromStream(java.io.InputStream is)
NOTE: Overriding MIME types sent from the server can be obnoxious to user's. See Internet Exploder 4 if you don't believe me.
is
- The InputStream to determine the MIME type fromIOException
- If an error occurspublic void setAllowUserInteraction(boolean allow)
allow
- true if user interaction should be allowed, false otherwisepublic static synchronized void setContentHandlerFactory(java.net.ContentHandlerFactory fac)
fac
- The ContentHandlerFactory for this applicationpublic static synchronized void setDefaultAllowUserInteraction(boolean allow)
allow
- true to allow user interaction, false otherwisepublic static synchronized void setDefaultRequestProperty(java.lang.String key, java.lang.String value)
key
- The request property name the default is being set forvalue
- The value to set the default topublic synchronized void setDefaultUseCaches(boolean use)
use
- true to use caches if possible by default, false otherwisepublic void setDoInput(boolean input)
input
- true if input is to be done, false otherwisepublic void setDoOutput(boolean output)
output
- ture if output is to be done, false otherwisepublic static void setFileNameMap(java.net.FileNameMap fileNameMap)
FileNameMap
object being used
to decode MIME types by file extension.
fileNameMap
- The FileNameMap
.public void setIfModifiedSince(long modified_since)
modified_since
- The new ifModifiedSince valuepublic void setRequestProperty(java.lang.String key, java.lang.String value)
key
- The name of the propertyvalue
- The value of the propertypublic void setUseCaches(boolean use_caches)
use_caches
- true if caching should be used if possible, false otherwisepublic String toString()
A URLConnection object is normally created by calling the openConnection() method of a URL object. This method is somewhat misnamed because it does not actually open the connection. Instead, it return an unconnected instance of this object. The caller then has the opportunity to set various connection options prior to calling the actual connect() method.
After the connection has been opened, there are a number of methods in this class that access various attributes of the data, typically represented by headers sent in advance of the actual data itself.
Also of note are the getInputStream and getContent() methods which allow the caller to retrieve the actual data from the connection. Note that for some types of connections, writing is also allowed. The setDoOutput() method must be called prior to connecing in order to enable this, then the getOutputStream method called after the connection in order to obtain a stream to write the output to.
The getContent() method is of particular note. This method returns an Object that encapsulates the data returned. There is no way do determine the type of object that will be returned in advance. This is determined by the actual content handlers as described in the description of that method.