Class CachingHttpURLConnection


  • public class CachingHttpURLConnection
    extends java.net.HttpURLConnection
    HttpURLConnection implementation that caches the data in a local file, if it is not already stored there.
    Author:
    P.J. Meisch ([email protected]).
    • Constructor Detail

      • CachingHttpURLConnection

        public CachingHttpURLConnection​(OfflineCache cache,
                                        java.net.HttpURLConnection delegate)
                                 throws java.io.IOException
        creates a CachingHttpURlConnection.
        Parameters:
        cache - the offline cache
        delegate - the delegate that provides the content
        Throws:
        java.io.IOException - if the output file cannot be created, or the input stream from the delegate cannot be retrieved
    • Method Detail

      • connect

        public void connect()
                     throws java.io.IOException
        Specified by:
        connect in class java.net.URLConnection
        Throws:
        java.io.IOException
      • addRequestProperty

        public void addRequestProperty​(java.lang.String key,
                                       java.lang.String value)
        Overrides:
        addRequestProperty in class java.net.URLConnection
      • getHeaderFieldKey

        public java.lang.String getHeaderFieldKey​(int n)
        Overrides:
        getHeaderFieldKey in class java.net.HttpURLConnection
      • setFixedLengthStreamingMode

        public void setFixedLengthStreamingMode​(int contentLength)
        Overrides:
        setFixedLengthStreamingMode in class java.net.HttpURLConnection
      • disconnect

        public void disconnect()
        Specified by:
        disconnect in class java.net.HttpURLConnection
      • setFixedLengthStreamingMode

        public void setFixedLengthStreamingMode​(long contentLength)
        Overrides:
        setFixedLengthStreamingMode in class java.net.HttpURLConnection
      • getAllowUserInteraction

        public boolean getAllowUserInteraction()
        Overrides:
        getAllowUserInteraction in class java.net.URLConnection
      • setChunkedStreamingMode

        public void setChunkedStreamingMode​(int chunklen)
        Overrides:
        setChunkedStreamingMode in class java.net.HttpURLConnection
      • getConnectTimeout

        public int getConnectTimeout()
        Overrides:
        getConnectTimeout in class java.net.URLConnection
      • getHeaderField

        public java.lang.String getHeaderField​(int n)
        Overrides:
        getHeaderField in class java.net.HttpURLConnection
      • getContent

        public java.lang.Object getContent()
                                    throws java.io.IOException
        Overrides:
        getContent in class java.net.URLConnection
        Throws:
        java.io.IOException
      • getContent

        public java.lang.Object getContent​(java.lang.Class[] classes)
                                    throws java.io.IOException
        Overrides:
        getContent in class java.net.URLConnection
        Throws:
        java.io.IOException
      • getContentEncoding

        public java.lang.String getContentEncoding()
        Overrides:
        getContentEncoding in class java.net.URLConnection
      • getContentLength

        public int getContentLength()
        Overrides:
        getContentLength in class java.net.URLConnection
      • getContentLengthLong

        public long getContentLengthLong()
        Overrides:
        getContentLengthLong in class java.net.URLConnection
      • getContentType

        public java.lang.String getContentType()
        Overrides:
        getContentType in class java.net.URLConnection
      • getDate

        public long getDate()
        Overrides:
        getDate in class java.net.URLConnection
      • getDefaultUseCaches

        public boolean getDefaultUseCaches()
        Overrides:
        getDefaultUseCaches in class java.net.URLConnection
      • getDoInput

        public boolean getDoInput()
        Overrides:
        getDoInput in class java.net.URLConnection
      • getDoOutput

        public boolean getDoOutput()
        Overrides:
        getDoOutput in class java.net.URLConnection
      • getErrorStream

        public java.io.InputStream getErrorStream()
        Overrides:
        getErrorStream in class java.net.HttpURLConnection
      • getExpiration

        public long getExpiration()
        Overrides:
        getExpiration in class java.net.URLConnection
      • getHeaderField

        public java.lang.String getHeaderField​(java.lang.String name)
        Overrides:
        getHeaderField in class java.net.URLConnection
      • getHeaderFieldDate

        public long getHeaderFieldDate​(java.lang.String name,
                                       long Default)
        Overrides:
        getHeaderFieldDate in class java.net.HttpURLConnection
      • getHeaderFieldInt

        public int getHeaderFieldInt​(java.lang.String name,
                                     int Default)
        Overrides:
        getHeaderFieldInt in class java.net.URLConnection
      • getHeaderFieldLong

        public long getHeaderFieldLong​(java.lang.String name,
                                       long Default)
        Overrides:
        getHeaderFieldLong in class java.net.URLConnection
      • getHeaderFields

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getHeaderFields()
        Overrides:
        getHeaderFields in class java.net.URLConnection
      • getIfModifiedSince

        public long getIfModifiedSince()
        Overrides:
        getIfModifiedSince in class java.net.URLConnection
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        return the delegate's InputStream wrapped in a WriteCacheFileInputStream or a FileInputStream in case when the data is already cached.
        Overrides:
        getInputStream in class java.net.URLConnection
        Returns:
        wrapping InputStream
        Throws:
        java.io.IOException
      • getInstanceFollowRedirects

        public boolean getInstanceFollowRedirects()
        Overrides:
        getInstanceFollowRedirects in class java.net.HttpURLConnection
      • getLastModified

        public long getLastModified()
        Overrides:
        getLastModified in class java.net.URLConnection
      • getOutputStream

        public java.io.OutputStream getOutputStream()
                                             throws java.io.IOException
        Overrides:
        getOutputStream in class java.net.URLConnection
        Throws:
        java.io.IOException
      • getPermission

        public java.security.Permission getPermission()
                                               throws java.io.IOException
        Overrides:
        getPermission in class java.net.HttpURLConnection
        Throws:
        java.io.IOException
      • getReadTimeout

        public int getReadTimeout()
        Overrides:
        getReadTimeout in class java.net.URLConnection
      • getRequestMethod

        public java.lang.String getRequestMethod()
        Overrides:
        getRequestMethod in class java.net.HttpURLConnection
      • getRequestProperties

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getRequestProperties()
        Overrides:
        getRequestProperties in class java.net.URLConnection
      • getRequestProperty

        public java.lang.String getRequestProperty​(java.lang.String key)
        Overrides:
        getRequestProperty in class java.net.URLConnection
      • getResponseCode

        public int getResponseCode()
                            throws java.io.IOException
        Overrides:
        getResponseCode in class java.net.HttpURLConnection
        Throws:
        java.io.IOException
      • getResponseMessage

        public java.lang.String getResponseMessage()
                                            throws java.io.IOException
        Overrides:
        getResponseMessage in class java.net.HttpURLConnection
        Throws:
        java.io.IOException
      • getURL

        public java.net.URL getURL()
        Overrides:
        getURL in class java.net.URLConnection
      • getUseCaches

        public boolean getUseCaches()
        Overrides:
        getUseCaches in class java.net.URLConnection
      • setAllowUserInteraction

        public void setAllowUserInteraction​(boolean allowuserinteraction)
        Overrides:
        setAllowUserInteraction in class java.net.URLConnection
      • setConnectTimeout

        public void setConnectTimeout​(int timeout)
        Overrides:
        setConnectTimeout in class java.net.URLConnection
      • setDefaultUseCaches

        public void setDefaultUseCaches​(boolean defaultusecaches)
        Overrides:
        setDefaultUseCaches in class java.net.URLConnection
      • setDoInput

        public void setDoInput​(boolean doinput)
        Overrides:
        setDoInput in class java.net.URLConnection
      • setDoOutput

        public void setDoOutput​(boolean dooutput)
        Overrides:
        setDoOutput in class java.net.URLConnection
      • setIfModifiedSince

        public void setIfModifiedSince​(long ifmodifiedsince)
        Overrides:
        setIfModifiedSince in class java.net.URLConnection
      • setInstanceFollowRedirects

        public void setInstanceFollowRedirects​(boolean followRedirects)
        Overrides:
        setInstanceFollowRedirects in class java.net.HttpURLConnection
      • setReadTimeout

        public void setReadTimeout​(int timeout)
        Overrides:
        setReadTimeout in class java.net.URLConnection
      • setRequestMethod

        public void setRequestMethod​(java.lang.String method)
                              throws java.net.ProtocolException
        Overrides:
        setRequestMethod in class java.net.HttpURLConnection
        Throws:
        java.net.ProtocolException
      • setRequestProperty

        public void setRequestProperty​(java.lang.String key,
                                       java.lang.String value)
        Overrides:
        setRequestProperty in class java.net.URLConnection
      • setUseCaches

        public void setUseCaches​(boolean usecaches)
        Overrides:
        setUseCaches in class java.net.URLConnection
      • usingProxy

        public boolean usingProxy()
        Specified by:
        usingProxy in class java.net.HttpURLConnection