public class FileURLConnection extends URLConnection
URLConnection.
This class is responsible for connecting, getting content and input stream of the file.
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches| Constructor and Description |
|---|
FileURLConnection(URL url)
Creates an instance of
FileURLConnection for establishing
a connection to the file pointed by this URL |
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
This methods will attempt to obtain the input stream of the file pointed
by this
URL. |
int |
getContentLength()
Returns the length of the file in bytes, or
-1 if the length cannot be
represented as an int. |
String |
getContentType()
Returns the content type of the resource.
|
String |
getHeaderField(int position)
Returns the header value at the field position
pos or null
if the header has fewer than pos fields. |
String |
getHeaderField(String key)
Returns the value of the header field specified by
key or null if there is no field with this name. |
String |
getHeaderFieldKey(int position)
Returns the name of the header field at the given position
posn or
null if there are fewer than posn fields. |
Map<String,List<String>> |
getHeaderFields()
Returns an unmodifiable map of the response-header fields and values.
|
InputStream |
getInputStream()
Returns the input stream of the object referred to by this
URLConnection
File 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" |
Permission |
getPermission()
Returns the permission, in this case the subclass, FilePermission object
which represents the permission necessary for this URLConnection to
establish the connection.
|
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, toStringpublic FileURLConnection(URL url)
FileURLConnection for establishing
a connection to the file pointed by this URLurl - The URL this connection is connected topublic void connect()
throws IOException
URL. If the file is a directory, it will return
that directory listing as an input stream.connect in class URLConnectionIOException - if an IO error occurs while connectingpublic String getHeaderField(String key)
URLConnectionkey or null if there is no field with this name. The base implementation of
this method returns always null.
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.
getHeaderField in class URLConnectionkey - the name of the header field.public String getHeaderFieldKey(int position)
URLConnectionposn or
null if there are fewer than posn fields. The base
implementation of this method returns always null.
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.
getHeaderFieldKey in class URLConnectionposition - the position of the header field which has to be returned.public String getHeaderField(int position)
URLConnectionpos or null
if the header has fewer than pos fields. The base
implementation of this method returns always null.
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.
getHeaderField in class URLConnectionposition - the field position of the response header.pos.public Map<String,List<String>> getHeaderFields()
URLConnectionSome 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.
getHeaderFields in class URLConnectionpublic int getContentLength()
-1 if the length cannot be
represented as an int. See getContentLengthLong() for a method that can
handle larger files.getContentLength in class URLConnectionpublic String getContentType()
getContentType in class URLConnectionpublic InputStream getInputStream() throws IOException
URLConnection
File 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"getInputStream in class URLConnectionIOException - if an IO error occurspublic Permission getPermission() throws IOException
getPermission in class URLConnectionIOException - if an IO exception occurs while creating the permission.