public class

JarURLConnection

extends JarURLConnection
java.lang.Object
   ↳ java.net.URLConnection
     ↳ java.net.JarURLConnection
       ↳ sun.net.www.protocol.jar.JarURLConnection

Summary

[Expand]
Inherited Fields
From class java.net.JarURLConnection
From class java.net.URLConnection
Public Constructors
JarURLConnection(URL url, Handler handler)
Public Methods
void addRequestProperty(String key, String value)
Adds a general request property specified by a key-value pair.
void connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
boolean getAllowUserInteraction()
Returns the value of the allowUserInteraction field for this object.
Object getContent()
Retrieves the contents of this URL connection.
int getContentLength()
Returns the value of the content-length header field.
String getContentType()
Returns the value of the content-type header field.
boolean getDefaultUseCaches()
Returns the default value of a URLConnection's useCaches flag.
String getHeaderField(String name)
Returns the value of the named header field.
InputStream getInputStream()
Returns an input stream that reads from this open connection.
JarEntry getJarEntry()
Return the JAR entry object for this connection, if any.
JarFile getJarFile()
Return the JAR file for this connection.
Permission getPermission()
Returns a permission object representing the permission necessary to make the connection represented by this object.
Map<StringList<String>> getRequestProperties()
Returns an unmodifiable Map of general request properties for this connection.
String getRequestProperty(String key)
Returns the value of the named general request property for this connection.
boolean getUseCaches()
Returns the value of this URLConnection's useCaches field.
void setAllowUserInteraction(boolean allowuserinteraction)
Set the value of the allowUserInteraction field of this URLConnection.
void setDefaultUseCaches(boolean defaultusecaches)
Sets the default value of the useCaches field to the specified value.
void setIfModifiedSince(long ifmodifiedsince)
Sets the value of the ifModifiedSince field of this URLConnection to the specified value.
void setRequestProperty(String key, String value)
Sets the general request property.
void setUseCaches(boolean usecaches)
Sets the value of the useCaches field of this URLConnection to the specified value.
[Expand]
Inherited Methods
From class java.net.JarURLConnection
From class java.net.URLConnection
From class java.lang.Object

Public Constructors

public JarURLConnection (URL url, Handler handler)

Public Methods

public void addRequestProperty (String key, String value)

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., "accept").
value the value associated with it.

public void connect ()

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

If the connect 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.

Throws
IOException

public boolean getAllowUserInteraction ()

Returns the value of the allowUserInteraction field for this object.

Returns
  • the value of the allowUserInteraction field for this object.

public Object getContent ()

Retrieves the contents of this URL connection.

This method first determines the content type of the object by calling the getContentType method. If this is the first time that the application has seen that specific content type, a content handler for that content type is created:

  1. If the application has set up a content handler factory instance using the setContentHandlerFactory method, the createContentHandler method of that instance is called with the content type as an argument; the result is a content handler for that content type.
  2. If no content handler factory has yet been set up, or if the factory's createContentHandler method returns null, then the application loads the class named:
             sun.net.www.content.<contentType>
         
    where <contentType> is formed by taking the content-type string, replacing all slash characters with a period ('.'), and all other non-alphanumeric characters with the underscore character '_'. The alphanumeric characters are specifically the 26 uppercase ASCII letters 'A' through 'Z', the 26 lowercase ASCII letters 'a' through 'z', and the 10 ASCII digits '0' through '9'. If the specified class does not exist, or is not a subclass of ContentHandler, then an UnknownServiceException is thrown.

Returns
  • the object fetched. The instanceof operator should be used to determine the specific kind of object returned.
Throws
IOException

public int getContentLength ()

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.

public String getContentType ()

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.

public boolean getDefaultUseCaches ()

Returns the default value of a URLConnection's useCaches flag.

Ths 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 URLConnection's useCaches flag.
See Also

public String getHeaderField (String name)

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 null if there is no such field in the header.

public InputStream getInputStream ()

Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.

Returns
  • an input stream that reads from this open connection.
Throws
IOException

public JarEntry getJarEntry ()

Return the JAR entry object for this connection, if any. This method returns null if the JAR file URL corresponding to this connection points to a JAR file and not a JAR file entry.

Returns
  • the JAR entry object for this connection, or null if the JAR URL for this connection points to a JAR file.
Throws
IOException

public JarFile getJarFile ()

Return the JAR file for this connection.

Returns
  • the JAR file for this connection. If the connection is a connection to an entry of a JAR file, the JAR file object is returned
Throws
IOException

public Permission getPermission ()

Returns a permission object representing the permission necessary to make the connection represented by this object. This method returns null if no permission is required to make the connection. By default, this method returns java.security.AllPermission. Subclasses should override this method and return the permission that best represents the permission required to make a a connection to the URL. For example, a URLConnection representing a file: URL would return a java.io.FilePermission object.

The permission returned may dependent upon the state of the connection. For example, the permission before connecting may be different from that after connecting. For example, an HTTP sever, say foo.com, may redirect the connection to a different host, say bar.com. Before connecting the permission returned by the connection will represent the permission needed to connect to foo.com, while the permission returned after connecting will be to bar.com.

Permissions are generally used for two purposes: to protect caches of objects obtained through URLConnections, and to check the right of a recipient to learn about a particular URL. In the first case, the permission should be obtained after the object has been obtained. For example, in an HTTP connection, this will represent the permission to connect to the host from which the data was ultimately fetched. In the second case, the permission should be obtained and tested before connecting.

Returns
  • the permission object representing the permission necessary to make the connection represented by this URLConnection.
Throws
IOException

public Map<StringList<String>> getRequestProperties ()

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.

public String getRequestProperty (String key)

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.

public boolean getUseCaches ()

Returns the value of this URLConnection's useCaches field.

Returns
  • the value of this URLConnection's useCaches field.
See Also

public void setAllowUserInteraction (boolean allowuserinteraction)

Set the value of the allowUserInteraction field of this URLConnection.

Parameters
allowuserinteraction the new value.

public void setDefaultUseCaches (boolean defaultusecaches)

Sets the default value of the useCaches field to the specified value.

Parameters
defaultusecaches the new value.
See Also

public void setIfModifiedSince (long ifmodifiedsince)

Sets the value of the ifModifiedSince field of this URLConnection to the specified value.

Parameters
ifmodifiedsince the new value.
See Also

public void setRequestProperty (String key, String value)

Sets the general request property.

Parameters
key the keyword by which the request is known (e.g., "accept").
value the value associated with it.

public void setUseCaches (boolean usecaches)

Sets the value of the useCaches field of this URLConnection 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 boolean indicating whether or not to allow caching
See Also