Class FileURLConnection
- java.lang.Object
-
- java.net.URLConnection
-
- libcore.net.url.FileURLConnection
-
public class FileURLConnection extends URLConnection
This subclass extendsURLConnection.This class is responsible for connecting, getting content and input stream of the file.
-
-
Field Summary
-
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches
-
-
Constructor Summary
Constructors Constructor Description FileURLConnection(URL url)Creates an instance ofFileURLConnectionfor establishing a connection to the file pointed by thisURL
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconnect()This methods will attempt to obtain the input stream of the file pointed by thisURL.intgetContentLength()Returns the length of the file in bytes, or-1if the length cannot be represented as anint.StringgetContentType()Returns the content type of the resource.StringgetHeaderField(int position)Returns the header value at the field positionposornullif the header has fewer thanposfields.StringgetHeaderField(String key)Returns the value of the header field specified bykeyornullif there is no field with this name.StringgetHeaderFieldKey(int position)Returns the name of the header field at the given positionposnornullif there are fewer thanposnfields.Map<String,List<String>>getHeaderFields()Returns an unmodifiable map of the response-header fields and values.InputStreamgetInputStream()Returns the input stream of the object referred to by thisURLConnectionFile Sample : "/ZIP211/+/harmony/tools/javac/resources/javac.properties" Invalid File Sample: "/ZIP/+/harmony/tools/javac/resources/javac.properties" "ZIP211/+/harmony/tools/javac/resources/javac.properties"PermissiongetPermission()Returns the permission, in this case the subclass, FilePermission object which represents the permission necessary for this URLConnection to establish the connection.-
Methods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldDate, getHeaderFieldInt, getIfModifiedSince, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
-
-
-
-
Constructor Detail
-
FileURLConnection
public FileURLConnection(URL url)
Creates an instance ofFileURLConnectionfor establishing a connection to the file pointed by thisURL- Parameters:
url- The URL this connection is connected to
-
-
Method Detail
-
connect
public void connect() throws IOExceptionThis methods will attempt to obtain the input stream of the file pointed by thisURL. If the file is a directory, it will return that directory listing as an input stream.- Specified by:
connectin classURLConnection- Throws:
IOException- if an IO error occurs while connecting
-
getHeaderField
public String getHeaderField(String key)
Description copied from class:URLConnectionReturns the value of the header field specified bykeyornullif there is no field with this name. The base implementation of this method returns alwaysnull.Some implementations (notably
HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.- Overrides:
getHeaderFieldin classURLConnection- Parameters:
key- the name of the header field.- Returns:
- the value of the header field.
-
getHeaderFieldKey
public String getHeaderFieldKey(int position)
Description copied from class:URLConnectionReturns the name of the header field at the given positionposnornullif there are fewer thanposnfields. The base implementation of this method returns alwaysnull.Some implementations (notably
HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.- Overrides:
getHeaderFieldKeyin classURLConnection- Parameters:
position- the position of the header field which has to be returned.- Returns:
- the header field name at the given position.
-
getHeaderField
public String getHeaderField(int position)
Description copied from class:URLConnectionReturns the header value at the field positionposornullif the header has fewer thanposfields. The base implementation of this method returns alwaysnull.Some implementations (notably
HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.- Overrides:
getHeaderFieldin classURLConnection- Parameters:
position- the field position of the response header.- Returns:
- the value of the field at position
pos.
-
getHeaderFields
public Map<String,List<String>> getHeaderFields()
Description copied from class:URLConnectionReturns an unmodifiable map of the response-header fields and values. The response-header field names are the key values of the map. The map values are lists of header field values associated with a particular key name.Some implementations (notably
HttpURLConnection) include a mapping for the null key; in HTTP's case, this maps to the HTTP status line and is treated as being at position 0 when indexing into the header fields.- Overrides:
getHeaderFieldsin classURLConnection- Returns:
- the response-header representing generic map.
-
getContentLength
public int getContentLength()
Returns the length of the file in bytes, or-1if the length cannot be represented as anint. SeegetContentLengthLong()for a method that can handle larger files.- Overrides:
getContentLengthin classURLConnection
-
getContentType
public String getContentType()
Returns the content type of the resource. Just takes a guess based on the name.- Overrides:
getContentTypein classURLConnection- Returns:
- the content type
-
getInputStream
public InputStream getInputStream() throws IOException
Returns the input stream of the object referred to by thisURLConnectionFile Sample : "/ZIP211/+/harmony/tools/javac/resources/javac.properties" Invalid File Sample: "/ZIP/+/harmony/tools/javac/resources/javac.properties" "ZIP211/+/harmony/tools/javac/resources/javac.properties"- Overrides:
getInputStreamin classURLConnection- Returns:
- input stream of the object
- Throws:
IOException- if an IO error occurs
-
getPermission
public Permission getPermission() throws IOException
Returns the permission, in this case the subclass, FilePermission object which represents the permission necessary for this URLConnection to establish the connection.- Overrides:
getPermissionin classURLConnection- Returns:
- the permission required for this URLConnection.
- Throws:
IOException- if an IO exception occurs while creating the permission.
-
-