Class JarURLConnectionImpl


public class JarURLConnectionImpl
extends JarURLConnection
This subclass extends URLConnection.

This class is responsible for connecting and retrieving resources from a Jar file which can be anywhere that can be referred to by an URL.

  • Constructor Details

  • Method Details

    • connect

      public void connect() throws IOException
      Description copied from class: URLConnection
      Opens a connection to the resource. This method will not reconnect to a resource after the initial connection has been closed.
      Specified by:
      connect in class URLConnection
      Throws:
      IOException - if an error occurs while connecting to the resource.
      See Also:
      URLConnection.connect()
    • getJarFile

      public JarFile getJarFile() throws IOException
      Returns the Jar file referred by this URLConnection.
      Specified by:
      getJarFile in class JarURLConnection
      Returns:
      the referenced JarFile object.
      Throws:
      IOException - thrown if an IO error occurs while connecting to the resource.
    • getJarEntry

      public JarEntry getJarEntry() throws IOException
      Returns the JarEntry of the entry referenced by this URLConnection.
      Overrides:
      getJarEntry in class JarURLConnection
      Returns:
      the JarEntry referenced
      Throws:
      IOException - if an IO error occurs while getting the entry
    • getInputStream

      public InputStream getInputStream() throws IOException
      Creates an input stream for reading from this URL Connection.
      Overrides:
      getInputStream in class URLConnection
      Returns:
      the input stream
      Throws:
      IOException - if an IO error occurs while connecting to the resource.
    • getContentType

      public String getContentType()
      Returns the content type of the resource. For jar file itself "x-java/jar" should be returned, for jar entries the content type of the entry should be returned. Returns non-null results ("content/unknown" for unknown types).
      Overrides:
      getContentType in class URLConnection
      Returns:
      the content type
    • getContentLength

      public int getContentLength()
      Returns the content length of the resource. Test cases reveal that if the URL is referring to a Jar file, this method answers a content-length returned by URLConnection. For jar entry it should return it's size. Otherwise, it will return -1.
      Overrides:
      getContentLength in class URLConnection
      Returns:
      the content length
    • getContent

      public Object getContent() throws IOException
      Returns the object pointed by this URL. If this URLConnection is pointing to a Jar File (no Jar Entry), this method will return a JarFile If there is a Jar Entry, it will return the object corresponding to the Jar entry content type.
      Overrides:
      getContent in class URLConnection
      Returns:
      a non-null object
      Throws:
      IOException - if an IO error occurred
      See Also:
      ContentHandler, ContentHandlerFactory, IOException, URLConnection.setContentHandlerFactory(ContentHandlerFactory)
    • 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 - thrown when an IO exception occurs while creating the permission.
    • getUseCaches

      public boolean getUseCaches()
      Description copied from class: URLConnection
      Returns the value of the flag which specifies whether this URLConnection allows to use caches.
      Overrides:
      getUseCaches in class URLConnection
      Returns:
      true if using caches is allowed, false otherwise.
    • setUseCaches

      public void setUseCaches​(boolean usecaches)
      Description copied from class: URLConnection
      Sets the flag indicating whether this connection allows to use caches or not. This method can only be called prior to the connection establishment.
      Overrides:
      setUseCaches in class URLConnection
      Parameters:
      usecaches - the value of the flag to be set.
      See Also:
      URLConnection.useCaches
    • getDefaultUseCaches

      public boolean getDefaultUseCaches()
      Description copied from class: URLConnection
      Returns the default setting whether this connection allows using caches.
      Overrides:
      getDefaultUseCaches in class URLConnection
      Returns:
      the value of the default setting defaultUseCaches.
      See Also:
      URLConnection.useCaches
    • setDefaultUseCaches

      public void setDefaultUseCaches​(boolean defaultusecaches)
      Description copied from class: URLConnection
      Sets the default value for the flag indicating whether this connection allows to use caches. Existing URLConnections are unaffected.
      Overrides:
      setDefaultUseCaches in class URLConnection
      Parameters:
      defaultusecaches - the default value of the flag to be used for new connections.
      See Also:
      URLConnection.useCaches