Class ContextConnection

java.lang.Object
java.net.URLConnection
org.apache.sling.launchpad.base.impl.ContextConnection

public class ContextConnection extends URLConnection
The ContextConnection extends the java.net.URLConnection to provide access to a resource which is available from LaunchpadContentProvider provided to Sling.

This class is implemented by actually connecting to a resource URL which is provided by the resource provider and delegating the relevant method calls. Currently only getContentLength(), getContentType(), getInputStream() and getLastModified() are supported.

  • Method Details

    • connect

      public void connect() throws IOException
      Accesses the the resource from the underlaying resource provider at the URL's path.
      Specified by:
      connect in class URLConnection
      Throws:
      IOException
    • getContentLength

      public int getContentLength()
      Returns the length in bytes of the resource or -1 if this connection has not been connected yet.
      Overrides:
      getContentLength in class URLConnection
    • getContentType

      public String getContentType()
      Returns a guess at the content type of the resource or null if this connection has not been connected yet.
      Overrides:
      getContentType in class URLConnection
    • getInputStream

      public InputStream getInputStream() throws IOException
      Returns a InputStream on the resource. If this connection is not connected yet, the conneciton is opened.
      Overrides:
      getInputStream in class URLConnection
      Throws:
      IOException - may be thrown if an error occurrs opening the connection or accessing the content as an InputStream.
    • getLastModified

      public long getLastModified()
      Returns the last modification timestamp of the resource or -1 if this connection has not been connected yet.
      Overrides:
      getLastModified in class URLConnection