public class

FileURLConnection

extends URLConnection
java.lang.Object
   ↳ java.net.URLConnection
     ↳ sun.net.www.URLConnection
       ↳ sun.net.www.protocol.file.FileURLConnection

Summary

[Expand]
Inherited Fields
From class sun.net.www.URLConnection
From class java.net.URLConnection
Protected Constructors
FileURLConnection(URL u, File file)
Public Methods
void connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
int getContentLength()
Call this routine to get the content-length associated with this object.
String getHeaderField(String name)
Returns the value of the named header field.
String getHeaderField(int n)
Return the value for the nth header field.
String getHeaderFieldKey(int n)
Return the key for the nth header field.
synchronized InputStream getInputStream()
Returns an input stream that reads from this open connection.
long getLastModified()
Returns the value of the last-modified header field.
Permission getPermission()
Returns a permission object representing the permission necessary to make the connection represented by this object.
MessageHeader getProperties()
Call this routine to get the property list for this object.
[Expand]
Inherited Methods
From class sun.net.www.URLConnection
From class java.net.URLConnection
From class java.lang.Object

Protected Constructors

protected FileURLConnection (URL u, File file)

Public Methods

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

Call this routine to get the content-length associated with this object.

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

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 String getHeaderField (int n)

Return the value for the nth header field. Returns null if there are fewer than n fields. This can be used in conjunction with getHeaderFieldKey to iterate through all the headers in the message.

Parameters
n an index, where n>=0
Returns
  • the value of the nth header field or null if there are fewer than n+1 fields

public String getHeaderFieldKey (int n)

Return the key for the nth header field. Returns null if there are fewer than n fields. This can be used to iterate through all the headers in the message.

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

public synchronized 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 long getLastModified ()

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 URLConnection was last modified, or 0 if not known.

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

Call this routine to get the property list for this object. Properties (like content-type) that have explicit getXX() methods associated with them should be accessed using those methods.