Class CloseableConnection

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    CloseableHttpConnection

    public class CloseableConnection
    extends java.lang.Object
    implements java.io.Closeable
    Closeable wrapper around a URLConnection.

    Only the needed methods of URLConnection are exposed.

    Additionally getResponseCode() from HttpURLConnection is available.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.net.URLConnection delegate  
    • Constructor Summary

      Constructors 
      Constructor Description
      CloseableConnection​(java.net.URLConnection delegate)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      does nothing.
      long getContentLength()
      delegates to URLConnection.getContentLengthLong()
      java.lang.String getHeaderField​(java.lang.String name)
      delegates to URLConnection.getHeaderField(String)
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaderFields()
      delegates to URLConnection.getHeaderFields()
      java.io.InputStream getInputStream()
      delegates to URLConnection.getInputStream()
      long getLastModified()
      delegates to URLConnection.getLastModified()
      java.net.URL getLocationHeaderFieldUrl()  
      java.security.Permission getPermission()
      delegates to URLConnection.getPermission()
      int getResponseCode()
      always returns HttpURLConnection.HTTP_OK.
      java.net.URL getURL()
      delegates to URLConnection.getURL()
      void setConnectTimeout​(int timeout)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • delegate

        private final java.net.URLConnection delegate
    • Constructor Detail

      • CloseableConnection

        CloseableConnection​(java.net.URLConnection delegate)
    • Method Detail

      • close

        public void close()
        does nothing. Subclasses may change this behavior
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • getResponseCode

        public int getResponseCode()
                            throws java.io.IOException
        always returns HttpURLConnection.HTTP_OK. Subclasses may change this behavior
        Throws:
        java.io.IOException
      • getURL

        public java.net.URL getURL()
        delegates to URLConnection.getURL()
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        delegates to URLConnection.getInputStream()
        Throws:
        java.io.IOException
      • getPermission

        public java.security.Permission getPermission()
                                               throws java.io.IOException
        delegates to URLConnection.getPermission()
        Throws:
        java.io.IOException
      • getHeaderFields

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaderFields()
        delegates to URLConnection.getHeaderFields()
      • getHeaderField

        public java.lang.String getHeaderField​(java.lang.String name)
        delegates to URLConnection.getHeaderField(String)
      • getLocationHeaderFieldUrl

        public java.net.URL getLocationHeaderFieldUrl()
                                               throws java.net.MalformedURLException
        Returns:
        HTTP header field "Location" as URL
        Throws:
        java.net.MalformedURLException - if the location string does not represent a valid URL
      • getLastModified

        public long getLastModified()
        delegates to URLConnection.getLastModified()
      • getContentLength

        public long getContentLength()
        delegates to URLConnection.getContentLengthLong()
      • setConnectTimeout

        public void setConnectTimeout​(int timeout)