Package com.sothawo.mapjfx.offline
Class CachingHttpsURLConnection
- java.lang.Object
-
- java.net.URLConnection
-
- java.net.HttpURLConnection
-
- javax.net.ssl.HttpsURLConnection
-
- com.sothawo.mapjfx.offline.CachingHttpsURLConnection
-
public class CachingHttpsURLConnection extends javax.net.ssl.HttpsURLConnection
HttpsURLConnection implementation that caches the data in a local file, if it is not already stored there.- Author:
- P.J. Meisch ([email protected]).
-
-
Field Summary
-
Fields inherited from class java.net.HttpURLConnection
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage
-
-
Constructor Summary
Constructors Constructor Description CachingHttpsURLConnection(OfflineCache cache, javax.net.ssl.HttpsURLConnection delegate)
creates a CachingHttpsURlConnection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addRequestProperty(java.lang.String key, java.lang.String value)
void
connect()
void
disconnect()
boolean
getAllowUserInteraction()
java.lang.String
getCipherSuite()
int
getConnectTimeout()
java.lang.Object
getContent()
java.lang.Object
getContent(java.lang.Class[] classes)
java.lang.String
getContentEncoding()
int
getContentLength()
long
getContentLengthLong()
java.lang.String
getContentType()
long
getDate()
boolean
getDefaultUseCaches()
boolean
getDoInput()
boolean
getDoOutput()
java.io.InputStream
getErrorStream()
long
getExpiration()
java.lang.String
getHeaderField(int n)
java.lang.String
getHeaderField(java.lang.String name)
long
getHeaderFieldDate(java.lang.String name, long Default)
int
getHeaderFieldInt(java.lang.String name, int Default)
java.lang.String
getHeaderFieldKey(int n)
long
getHeaderFieldLong(java.lang.String name, long Default)
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getHeaderFields()
javax.net.ssl.HostnameVerifier
getHostnameVerifier()
long
getIfModifiedSince()
java.io.InputStream
getInputStream()
return the delegate's InputStream wrapped in aWriteCacheFileInputStream
or a FileInputStream in case when the data is already cached.boolean
getInstanceFollowRedirects()
long
getLastModified()
java.security.cert.Certificate[]
getLocalCertificates()
java.security.Principal
getLocalPrincipal()
java.io.OutputStream
getOutputStream()
java.security.Principal
getPeerPrincipal()
java.security.Permission
getPermission()
int
getReadTimeout()
java.lang.String
getRequestMethod()
java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getRequestProperties()
java.lang.String
getRequestProperty(java.lang.String key)
int
getResponseCode()
java.lang.String
getResponseMessage()
java.security.cert.Certificate[]
getServerCertificates()
javax.net.ssl.SSLSocketFactory
getSSLSocketFactory()
java.net.URL
getURL()
boolean
getUseCaches()
void
setAllowUserInteraction(boolean allowuserinteraction)
void
setChunkedStreamingMode(int chunklen)
void
setConnectTimeout(int timeout)
void
setDefaultUseCaches(boolean defaultusecaches)
void
setDoInput(boolean doinput)
void
setDoOutput(boolean dooutput)
void
setFixedLengthStreamingMode(int contentLength)
void
setFixedLengthStreamingMode(long contentLength)
void
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
void
setIfModifiedSince(long ifmodifiedsince)
void
setInstanceFollowRedirects(boolean followRedirects)
void
setReadTimeout(int timeout)
void
setRequestMethod(java.lang.String method)
void
setRequestProperty(java.lang.String key, java.lang.String value)
void
setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
void
setUseCaches(boolean usecaches)
boolean
usingProxy()
-
Methods inherited from class javax.net.ssl.HttpsURLConnection
getDefaultHostnameVerifier, getDefaultSSLSocketFactory, setDefaultHostnameVerifier, setDefaultSSLSocketFactory
-
Methods inherited from class java.net.HttpURLConnection
getFollowRedirects, setAuthenticator, setFollowRedirects
-
Methods inherited from class java.net.URLConnection
getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getFileNameMap, guessContentTypeFromName, guessContentTypeFromStream, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setFileNameMap, toString
-
-
-
-
Constructor Detail
-
CachingHttpsURLConnection
public CachingHttpsURLConnection(OfflineCache cache, javax.net.ssl.HttpsURLConnection delegate) throws java.io.IOException
creates a CachingHttpsURlConnection.- Parameters:
cache
- the offline cachedelegate
- 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 classjava.net.URLConnection
- Throws:
java.io.IOException
-
getCipherSuite
public java.lang.String getCipherSuite()
- Specified by:
getCipherSuite
in classjavax.net.ssl.HttpsURLConnection
-
getLocalCertificates
public java.security.cert.Certificate[] getLocalCertificates()
- Specified by:
getLocalCertificates
in classjavax.net.ssl.HttpsURLConnection
-
getServerCertificates
public java.security.cert.Certificate[] getServerCertificates() throws javax.net.ssl.SSLPeerUnverifiedException
- Specified by:
getServerCertificates
in classjavax.net.ssl.HttpsURLConnection
- Throws:
javax.net.ssl.SSLPeerUnverifiedException
-
addRequestProperty
public void addRequestProperty(java.lang.String key, java.lang.String value)
- Overrides:
addRequestProperty
in classjava.net.URLConnection
-
getPeerPrincipal
public java.security.Principal getPeerPrincipal() throws javax.net.ssl.SSLPeerUnverifiedException
- Overrides:
getPeerPrincipal
in classjavax.net.ssl.HttpsURLConnection
- Throws:
javax.net.ssl.SSLPeerUnverifiedException
-
getLocalPrincipal
public java.security.Principal getLocalPrincipal()
- Overrides:
getLocalPrincipal
in classjavax.net.ssl.HttpsURLConnection
-
getHeaderFieldKey
public java.lang.String getHeaderFieldKey(int n)
- Overrides:
getHeaderFieldKey
in classjava.net.HttpURLConnection
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength)
- Overrides:
setFixedLengthStreamingMode
in classjava.net.HttpURLConnection
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(long contentLength)
- Overrides:
setFixedLengthStreamingMode
in classjava.net.HttpURLConnection
-
disconnect
public void disconnect()
- Specified by:
disconnect
in classjava.net.HttpURLConnection
-
setChunkedStreamingMode
public void setChunkedStreamingMode(int chunklen)
- Overrides:
setChunkedStreamingMode
in classjava.net.HttpURLConnection
-
getHeaderField
public java.lang.String getHeaderField(int n)
- Overrides:
getHeaderField
in classjava.net.HttpURLConnection
-
getAllowUserInteraction
public boolean getAllowUserInteraction()
- Overrides:
getAllowUserInteraction
in classjava.net.URLConnection
-
getConnectTimeout
public int getConnectTimeout()
- Overrides:
getConnectTimeout
in classjava.net.URLConnection
-
getContent
public java.lang.Object getContent() throws java.io.IOException
- Overrides:
getContent
in classjava.net.URLConnection
- Throws:
java.io.IOException
-
getContent
public java.lang.Object getContent(java.lang.Class[] classes) throws java.io.IOException
- Overrides:
getContent
in classjava.net.URLConnection
- Throws:
java.io.IOException
-
getContentEncoding
public java.lang.String getContentEncoding()
- Overrides:
getContentEncoding
in classjava.net.URLConnection
-
getContentLength
public int getContentLength()
- Overrides:
getContentLength
in classjava.net.URLConnection
-
getContentLengthLong
public long getContentLengthLong()
- Overrides:
getContentLengthLong
in classjava.net.URLConnection
-
getContentType
public java.lang.String getContentType()
- Overrides:
getContentType
in classjava.net.URLConnection
-
getDate
public long getDate()
- Overrides:
getDate
in classjava.net.URLConnection
-
getDefaultUseCaches
public boolean getDefaultUseCaches()
- Overrides:
getDefaultUseCaches
in classjava.net.URLConnection
-
getDoInput
public boolean getDoInput()
- Overrides:
getDoInput
in classjava.net.URLConnection
-
getDoOutput
public boolean getDoOutput()
- Overrides:
getDoOutput
in classjava.net.URLConnection
-
getErrorStream
public java.io.InputStream getErrorStream()
- Overrides:
getErrorStream
in classjava.net.HttpURLConnection
-
getExpiration
public long getExpiration()
- Overrides:
getExpiration
in classjava.net.URLConnection
-
getHeaderField
public java.lang.String getHeaderField(java.lang.String name)
- Overrides:
getHeaderField
in classjava.net.URLConnection
-
getHeaderFieldDate
public long getHeaderFieldDate(java.lang.String name, long Default)
- Overrides:
getHeaderFieldDate
in classjava.net.HttpURLConnection
-
getHeaderFieldInt
public int getHeaderFieldInt(java.lang.String name, int Default)
- Overrides:
getHeaderFieldInt
in classjava.net.URLConnection
-
getHeaderFieldLong
public long getHeaderFieldLong(java.lang.String name, long Default)
- Overrides:
getHeaderFieldLong
in classjava.net.URLConnection
-
getHeaderFields
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
- Overrides:
getHeaderFields
in classjava.net.URLConnection
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
- Overrides:
getHostnameVerifier
in classjavax.net.ssl.HttpsURLConnection
-
getIfModifiedSince
public long getIfModifiedSince()
- Overrides:
getIfModifiedSince
in classjava.net.URLConnection
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
return the delegate's InputStream wrapped in aWriteCacheFileInputStream
or a FileInputStream in case when the data is already cached.- Overrides:
getInputStream
in classjava.net.URLConnection
- Returns:
- wrapping InputStream
- Throws:
java.io.IOException
-
getInstanceFollowRedirects
public boolean getInstanceFollowRedirects()
- Overrides:
getInstanceFollowRedirects
in classjava.net.HttpURLConnection
-
getLastModified
public long getLastModified()
- Overrides:
getLastModified
in classjava.net.URLConnection
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
- Overrides:
getOutputStream
in classjava.net.URLConnection
- Throws:
java.io.IOException
-
getPermission
public java.security.Permission getPermission() throws java.io.IOException
- Overrides:
getPermission
in classjava.net.HttpURLConnection
- Throws:
java.io.IOException
-
getReadTimeout
public int getReadTimeout()
- Overrides:
getReadTimeout
in classjava.net.URLConnection
-
getRequestMethod
public java.lang.String getRequestMethod()
- Overrides:
getRequestMethod
in classjava.net.HttpURLConnection
-
getRequestProperties
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestProperties()
- Overrides:
getRequestProperties
in classjava.net.URLConnection
-
getRequestProperty
public java.lang.String getRequestProperty(java.lang.String key)
- Overrides:
getRequestProperty
in classjava.net.URLConnection
-
getResponseCode
public int getResponseCode() throws java.io.IOException
- Overrides:
getResponseCode
in classjava.net.HttpURLConnection
- Throws:
java.io.IOException
-
getResponseMessage
public java.lang.String getResponseMessage() throws java.io.IOException
- Overrides:
getResponseMessage
in classjava.net.HttpURLConnection
- Throws:
java.io.IOException
-
getSSLSocketFactory
public javax.net.ssl.SSLSocketFactory getSSLSocketFactory()
- Overrides:
getSSLSocketFactory
in classjavax.net.ssl.HttpsURLConnection
-
getURL
public java.net.URL getURL()
- Overrides:
getURL
in classjava.net.URLConnection
-
getUseCaches
public boolean getUseCaches()
- Overrides:
getUseCaches
in classjava.net.URLConnection
-
setAllowUserInteraction
public void setAllowUserInteraction(boolean allowuserinteraction)
- Overrides:
setAllowUserInteraction
in classjava.net.URLConnection
-
setConnectTimeout
public void setConnectTimeout(int timeout)
- Overrides:
setConnectTimeout
in classjava.net.URLConnection
-
setDefaultUseCaches
public void setDefaultUseCaches(boolean defaultusecaches)
- Overrides:
setDefaultUseCaches
in classjava.net.URLConnection
-
setDoInput
public void setDoInput(boolean doinput)
- Overrides:
setDoInput
in classjava.net.URLConnection
-
setDoOutput
public void setDoOutput(boolean dooutput)
- Overrides:
setDoOutput
in classjava.net.URLConnection
-
setHostnameVerifier
public void setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
- Overrides:
setHostnameVerifier
in classjavax.net.ssl.HttpsURLConnection
-
setIfModifiedSince
public void setIfModifiedSince(long ifmodifiedsince)
- Overrides:
setIfModifiedSince
in classjava.net.URLConnection
-
setInstanceFollowRedirects
public void setInstanceFollowRedirects(boolean followRedirects)
- Overrides:
setInstanceFollowRedirects
in classjava.net.HttpURLConnection
-
setReadTimeout
public void setReadTimeout(int timeout)
- Overrides:
setReadTimeout
in classjava.net.URLConnection
-
setRequestMethod
public void setRequestMethod(java.lang.String method) throws java.net.ProtocolException
- Overrides:
setRequestMethod
in classjava.net.HttpURLConnection
- Throws:
java.net.ProtocolException
-
setRequestProperty
public void setRequestProperty(java.lang.String key, java.lang.String value)
- Overrides:
setRequestProperty
in classjava.net.URLConnection
-
setSSLSocketFactory
public void setSSLSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
- Overrides:
setSSLSocketFactory
in classjavax.net.ssl.HttpsURLConnection
-
setUseCaches
public void setUseCaches(boolean usecaches)
- Overrides:
setUseCaches
in classjava.net.URLConnection
-
usingProxy
public boolean usingProxy()
- Specified by:
usingProxy
in classjava.net.HttpURLConnection
-
-