Interface URL2Connection

All Known Implementing Classes:
URL2ConnectionBase, URL2ConnectionWrapper

public interface URL2Connection
An interface which is analogous to the awful URLConnection but designed for implementation and extension
  • Method Details

    • isConnected

      boolean isConnected()
      Return true if the connection has been made
    • getMethod

      default String getMethod()
      Return the method - defaults to "GET"
    • getRequestInputStream

      default InputStream getRequestInputStream() throws IOException
      Return the InputStream for the request, which defaults to null.
      Throws:
      IOException
    • getURL

      URL2 getURL()
      Get the URL. Note the origin's ReferrerPolicy is used
    • getInputStream

      InputStream getInputStream() throws IOException
      Return the InputStream for the response. Will trigger a connection
      Throws:
      IOException
    • getLegacyURLConnection

      URLConnection getLegacyURLConnection() throws IOException
      If this instance wraps a URLConnection, return that, otherwise return null
      Throws:
      IOException
    • getCode

      int getCode() throws IOException
      Return the response code, the logic for this will depend on the scheme but which ideally should match HTTP Will trigger a connection
      Throws:
      IOException
    • getResponseHeaders

      Map<String,List<String>> getResponseHeaders() throws IOException
      Return a modifiable map of the Response headers. It's usually preferable to call getResponseHeader(java.lang.String) to retrieve a single header, as that handles case folding. Will trigger a connection.
      Throws:
      IOException
    • getRequestHeaders

      Map<String,List<String>> getRequestHeaders()
      Return a modifiable map of the Request headers It's usually preferable to call getRequestHeader(java.lang.String) to retrieve a single header, as that handles case folding.
    • getRequestHeader

      String getRequestHeader(String key)
      Return a previously-set Request header
    • setRequestHeader

      void setRequestHeader(String key, String value)
      Set a request header. Replaces all other headers with this name.
      Parameters:
      key - the header name, which is case-insensitive
      value - the value name, or null to remove the header.
      Throws:
      IllegalStateException - if we're already connected
    • getResponseHeader

      String getResponseHeader(String key) throws IOException
      Return a response header if set, or null otherwise. If multiple headers, returns the first.
      Parameters:
      key - the header name, which is case-insensitive
      Throws:
      IOException
    • getResponseDateHeader

      Date getResponseDateHeader(String key) throws IOException
      Return a response header as a Date if set and a valid date, or null otherwise. If multiple headers, returns the first.
      Parameters:
      key - the header name, which is case-insensitive
      Throws:
      IOException
    • getRequestDateHeader

      Date getRequestDateHeader(String key)
      Return a request header as a Date (if set and a valid date), or null otherwise. If multiple headers, returns the first.
      Parameters:
      key - the header name, which is case-insensitive
    • setRequestDateHeader

      void setRequestDateHeader(String key, Date value)
      Set a request header as a Date.
      Parameters:
      key - the header name, which is case-insensitive
      value - the date value
      Throws:
      IllegalStateException - if we're already connected
    • setCallbackHandler

      void setCallbackHandler(CallbackHandler handler)
      Set the CallbackHandler that should be used for any authorization callbacks required on this connection
    • getCallbackHandler

      CallbackHandler getCallbackHandler()
    • getLastModified

      default long getLastModified() throws IOException
      Return the "Last-Modified" header as a long describing milliseconds since the UNIX epoch, or 0 if not set
      Throws:
      IOException
    • getIfModifiedSince

      default long getIfModifiedSince() throws IOException
      Return the "If-Modified-Since" header as a long describing milliseconds since the UNIX epoch, or 0 if not set
      Throws:
      IOException
    • connect

      void connect() throws IOException
      Open the network connection
      Throws:
      IOException