FileDocCategorySizeDatePackage
ResponseCache.javaAPI DocAndroid 1.5 API6667Wed May 06 22:41:04 BST 2009java.net

ResponseCache

public abstract class ResponseCache extends Object
This class is an implementation of {@code URLConnection} caches intended primarily for the according stream handler implementations.

The system's default cache can be registered by invoking the method {@code setDefault(ResponseCache)} and be retrieved by invoking the method {@code getDefault()}. If {@code URLConnection#useCaches} is set, {@code URLConnection} class will use {@code ResponseCache} to store and get resources.

Whether the resource is cached depends on the implementation of {@code ResponseCache}. If so, a {@code CacheResponse} is returned from which the stream handler reads. If the stream handler fails to get a resource from the cache, it must get the resource from its original location.

To write to the cache, the protocol handlers call {@code put()}, upon which a {@code CacheRequest} is supplied to which the resources are written.

see
#put(URI, URLConnection)
see
CacheRequest
see
CacheResponse
see
URLConnection
see
URLStreamHandler
since
Android 1.0

Fields Summary
private static ResponseCache
_defaultResponseCache
private static NetPermission
getResponseCachepermission
private static NetPermission
setResponseCachepermission
Constructors Summary
public ResponseCache()
Creates a new instance of this class.

since
Android 1.0

        super();
    
Methods Summary
private static voidcheckGetResponseCachePermission()

 //$NON-NLS-1$

    /*
     * check getResponseCache permission. getDefault method requires
     * "getResponseCache" permission if a security manager is installed.
     */
        
        SecurityManager sm = System.getSecurityManager();
        if (null != sm) {
            sm.checkPermission(getResponseCachepermission);
        }
    
private static voidcheckSetResponseCachePermission()

        SecurityManager sm = System.getSecurityManager();
        if (null != sm) {
            sm.checkPermission(setResponseCachepermission);
        }
    
public abstract java.net.CacheResponseget(java.net.URI uri, java.lang.String rqstMethod, java.util.Map rqstHeaders)
Gets the cached response according to the requesting URI, method and headers.

param
uri the requesting URI.
param
rqstMethod the requesting method.
param
rqstHeaders a map of requesting headers.
return
the {@code CacheResponse} object if the request is available in the cache or {@code null} otherwise.
throws
IOException if an I/O error occurs while getting the cached data.
throws
IllegalArgumentException if any one of the parameters is set to {@code null}.
since
Android 1.0

public static java.net.ResponseCachegetDefault()
Gets the default response cache of the system.

return
the default {@code ResponseCache}.
throws
SecurityException if a security manager is installed but it doesn't have the {@code NetPermission("getResponseCache")}.
since
Android 1.0

        checkGetResponseCachePermission();
        return _defaultResponseCache;
    
public abstract java.net.CacheRequestput(java.net.URI uri, java.net.URLConnection conn)
Allows the protocol handler to cache data after retrieving resources. The {@code ResponseCache} decides whether the resource data should be cached or not. If so, this method returns a {@code CacheRequest} with a {@code WriteableByteChannel} to put the resource data down. Otherwise, this method returns {@code null}.

param
uri the reference to the requested resource.
param
conn the connection to fetch the response.
return
a CacheRequest object with a WriteableByteChannel if the resource has to be cached, {@code null} otherwise.
throws
IOException if an I/O error occurs while adding the resource.
throws
IllegalArgumentException if any one of the parameters is set to {@code null}.
since
Android 1.0

public static voidsetDefault(java.net.ResponseCache responseCache)
Sets the default response cache of the system. Removes the system's default {@code ResponseCache} if the parameter {@code responseCache} is set to {@code null}. This setting may be ignored by some non-standard protocols.

param
responseCache the {@code ResponseCache} instance to set as default or {@code null} to remove the current default {@code ResponseCache}.
throws
SecurityException if a security manager is installed but it doesn't have the {@code NetPermission("setResponseCache")}.
since
Android 1.0

        checkSetResponseCachePermission();
        _defaultResponseCache = responseCache;