Class FileURLConnection


  • public class FileURLConnection
    extends URLConnection
    This subclass extends URLConnection.

    This class is responsible for connecting, getting content and input stream of the file.

    • Constructor Detail

      • FileURLConnection

        public FileURLConnection​(URL url)
        Creates an instance of FileURLConnection for establishing a connection to the file pointed by this URL
        Parameters:
        url - The URL this connection is connected to
    • Method Detail

      • connect

        public void connect()
                     throws IOException
        This methods will attempt to obtain the input stream of the file pointed by this URL. If the file is a directory, it will return that directory listing as an input stream.
        Specified by:
        connect in class URLConnection
        Throws:
        IOException - if an IO error occurs while connecting
      • getHeaderField

        public String getHeaderField​(String key)
        Description copied from class: URLConnection
        Returns the value of the header field specified by key 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.

        Overrides:
        getHeaderField in class URLConnection
        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: URLConnection
        Returns the name of the header field at the given position posn 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.

        Overrides:
        getHeaderFieldKey in class URLConnection
        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: URLConnection
        Returns the header value at the field position pos 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.

        Overrides:
        getHeaderField in class URLConnection
        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: URLConnection
        Returns 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:
        getHeaderFields in class URLConnection
        Returns:
        the response-header representing generic map.
      • getContentLength

        public int getContentLength()
        Returns the length of the file in bytes, or -1 if the length cannot be represented as an int. See getContentLengthLong() for a method that can handle larger files.
        Overrides:
        getContentLength in class URLConnection
      • getContentType

        public String getContentType()
        Returns the content type of the resource. Just takes a guess based on the name.
        Overrides:
        getContentType in class URLConnection
        Returns:
        the content type
      • getInputStream

        public InputStream getInputStream()
                                   throws IOException
        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"
        Overrides:
        getInputStream in class URLConnection
        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:
        getPermission in class URLConnection
        Returns:
        the permission required for this URLConnection.
        Throws:
        IOException - if an IO exception occurs while creating the permission.