APIdia Launch Partner
Top Description Fields Constructors Methods
sun.net.www.protocol.file

public Class FileURLConnection

extends URLConnection
Class Inheritance
Imports
java.io.BufferedInputStream, .ByteArrayInputStream, .File, .FileInputStream, .FileNotFoundException, .FilePermission, .IOException, .InputStream, java.net.FileNameMap, .MalformedURLException, .URL, java.security.Permission, java.text.Collator, .SimpleDateFormat, java.util.Arrays, .Date, .List, .Locale, .Map, .TimeZone, sun.net.www.MessageHeader, .ParseUtil, .URLConnection

Open a file input stream given a URL.
Authors
James Gosling, Steven B. Byrne

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private List<String>
private boolean
private final File
private static final boolean
private boolean
private InputStream
private boolean
private static final String
private long
private long
pack-priv Permission
private static final String
Inherited from sun.net.www.URLConnection:
properties

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public synchronized void
public void
connect()

Implements abstract java.net.URLConnection.connect.

If already connected, then this method is a no-op.

protected synchronized void
ensureCanServeHeaders()

Overrides sun.net.www.URLConnection.ensureCanServeHeaders.

This method is called whenever the headers related methods are called on the URLConnection.

public int
getContentLength()

Overrides sun.net.www.URLConnection.getContentLength.

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

public long
getContentLengthLong()

Overrides java.net.URLConnection.getContentLengthLong.

Returns the value of the content-length header field as a long.

public String
getHeaderField(String name)

Overrides sun.net.www.URLConnection.getHeaderField.

Returns the value of the named header field.

public String
getHeaderField(int n)

Overrides sun.net.www.URLConnection.getHeaderField.

Return the value for the nth header field.

public String
getHeaderFieldKey(int n)

Overrides sun.net.www.URLConnection.getHeaderFieldKey.

Return the key for the nth header field.

public Map<String, List<String>>
getHeaderFields()

Overrides sun.net.www.URLConnection.getHeaderFields.

Returns an unmodifiable Map of the header fields.

public synchronized InputStream
getInputStream()

Overrides java.net.URLConnection.getInputStream.

Returns an input stream that reads from this open connection.

public long
getLastModified()

Overrides java.net.URLConnection.getLastModified.

Returns the value of the last-modified header field.

public Permission
getPermission()

Overrides java.net.URLConnection.getPermission.

Deprecated for removal since 25.

Returns a permission object representing the permission necessary to make the connection represented by this object.

public MessageHeader
getProperties()

Overrides sun.net.www.URLConnection.getProperties.

Call this routine to get the property list for this object.

private void
pack-priv static void
requireFtpFallbackEnabled()

Throw MalformedURLException if the FTP fallback feature for non-local file URLs is not explicitly enabled via system property.

Inherited from sun.net.www.URLConnection:
addRequestPropertycanCacheclosegetContentTypegetRequestPropertiesgetRequestPropertyisProxiedHostsetContentLengthsetContentTypesetPropertiessetProxiedHostsetRequestProperty

Field Detail

CONTENT_LENGTHback to summary
private static final String CONTENT_LENGTH
CONTENT_TYPEback to summary
private static final String CONTENT_TYPE
directoryListingback to summary
private List<String> directoryListing
existsback to summary
private boolean exists
fileback to summary
private final File file
FTP_FALLBACK_ENABLEDback to summary
private static final boolean FTP_FALLBACK_ENABLED
initializedHeadersback to summary
private boolean initializedHeaders
isback to summary
private InputStream is
isDirectoryback to summary
private boolean isDirectory
LAST_MODIFIEDback to summary
private static final String LAST_MODIFIED
lastModifiedback to summary
private long lastModified
lengthback to summary
private long length
permissionback to summary
pack-priv Permission permission
TEXT_PLAINback to summary
private static final String TEXT_PLAIN

Constructor Detail

FileURLConnectionback to summary
protected FileURLConnection(URL u, File file)

Method Detail

closeInputStreamback to summary
public synchronized void closeInputStream() throws IOException
connectback to summary
public void connect() throws IOException

Implements abstract java.net.URLConnection.connect.

If already connected, then this method is a no-op. If not already connected, then this method does readability checks for the File.

If the File is a directory then the readability check is done by verifying that File.list() does not return null. On the other hand, if the File is not a directory, then this method constructs a temporary FileInputStream for the File and lets the FileInputStream's constructor implementation do the necessary readability checks. That temporary FileInputStream is closed before returning from this method.

In either case, if the readability checks fail, then an IOException is thrown from this method and the FileURLConnection stays unconnected.

A normal return from this method implies that the FileURLConnection is connected and the readability checks have passed for the File.

Note

the semantics of FileURLConnection object is that the results of the various URLConnection calls, such as getContentType, getInputStream or getContentLength reflect whatever was true when connect was called.

Annotations
@Override
Exceptions
IOException:

Doc from java.net.URLConnection.connect.

if an I/O error occurs while opening the connection.

ensureCanServeHeadersback to summary
protected synchronized void ensureCanServeHeaders() throws IOException

Overrides sun.net.www.URLConnection.ensureCanServeHeaders.

Doc from sun.net.www.URLConnection.ensureCanServeHeaders.

This method is called whenever the headers related methods are called on the URLConnection. This method does any necessary checks and initializations to make sure that the headers can be served. If this URLConnection cannot serve the headers, then this method throws an IOException.

Annotations
@Override
Exceptions
IOException:
if the headers cannot be served
getContentLengthback to summary
public int getContentLength()

Overrides sun.net.www.URLConnection.getContentLength.

Doc from sun.net.www.URLConnection.getContentLength.

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

Annotations
@Override
getContentLengthLongback to summary
public long getContentLengthLong()

Overrides java.net.URLConnection.getContentLengthLong.

Doc from java.net.URLConnection.getContentLengthLong.

Returns the value of the content-length header field as a long.

Annotations
@Override
getHeaderFieldback to summary
public String getHeaderField(String name)

Overrides sun.net.www.URLConnection.getHeaderField.

Doc from java.net.URLConnection.getHeaderField.

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.

Annotations
@Override
getHeaderFieldback to summary
public String getHeaderField(int n)

Overrides sun.net.www.URLConnection.getHeaderField.

Doc from sun.net.www.URLConnection.getHeaderField.

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.

Annotations
@Override
getHeaderFieldKeyback to summary
public String getHeaderFieldKey(int n)

Overrides sun.net.www.URLConnection.getHeaderFieldKey.

Doc from sun.net.www.URLConnection.getHeaderFieldKey.

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.

Annotations
@Override
getHeaderFieldsback to summary
public Map<String, List<String>> getHeaderFields()

Overrides sun.net.www.URLConnection.getHeaderFields.

Doc from java.net.URLConnection.getHeaderFields.

Returns an unmodifiable Map of the header fields. The Map keys are Strings that represent the response-header field names. Each Map value is an unmodifiable List of Strings that represents the corresponding field values. This method is overridden by the subclasses of URLConnection. In the implementation of these methods, if a given key has multiple corresponding values, they must be returned in the order they were added, preserving the insertion-order.

Annotations
@Override
getInputStreamback to summary
public synchronized InputStream getInputStream() throws IOException

Overrides java.net.URLConnection.getInputStream.

Doc from java.net.URLConnection.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.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while creating the input stream.
getLastModifiedback to summary
public long getLastModified()

Overrides java.net.URLConnection.getLastModified.

Doc from java.net.URLConnection.getLastModified.

Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT.

Annotations
@Override
getPermissionback to summary
public Permission getPermission() throws IOException

Overrides java.net.URLConnection.getPermission.

Doc from java.net.URLConnection.getPermission.

Deprecated

for removal since 25.

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 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.

Annotations
@Override
@Deprecated
since:25
forRemoval:true
@SuppressWarnings:removal
Exceptions
IOException:
if the computation of the permission requires network or file I/O and an exception occurs while computing it.
getPropertiesback to summary
public MessageHeader getProperties()

Overrides sun.net.www.URLConnection.getProperties.

Doc from sun.net.www.URLConnection.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.

Annotations
@Override
initializeHeadersback to summary
private void initializeHeaders()
requireFtpFallbackEnabledback to summary
pack-priv static void requireFtpFallbackEnabled() throws MalformedURLException

Throw MalformedURLException if the FTP fallback feature for non-local file URLs is not explicitly enabled via system property.

Exceptions
MalformedURLException:
if FTP fallback is not enabled
See Also
FTP_FALLBACK_ENABLED