Class FileURLConnection

java.lang.Object
java.net.URLConnection
libcore.net.url.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 Details

    • 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 Details

    • 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
    • getContentLength

      public int getContentLength()
      Returns the length of the file in bytes.
      Overrides:
      getContentLength in class URLConnection
      Returns:
      the length of the file
      See Also:
      getContentType()
    • 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.