|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.android.sdklib.internal.repository.DownloadCache
public class DownloadCache
A simple cache for the XML resources handled by the SDK Manager.
Callers should useopenDirectUrl(java.lang.String, org.apache.http.Header[], com.android.sdklib.internal.repository.ITaskMonitor) to download "large files"
that should not be cached (like actual installation packages which are several MBs big)
and call openCachedUrl(String, ITaskMonitor) to download small XML files.
The cache can work in 3 different strategies (direct is a pass-through, fresh-cache is the
default and tries to update resources if they are older than 10 minutes by respecting
either ETag or Last-Modified, and finally server-cache is a strategy to always serve
cached entries if present.)
| Nested Class Summary | |
|---|---|
static class |
DownloadCache.Strategy
|
| Constructor Summary | |
|---|---|
DownloadCache(DownloadCache.Strategy strategy)
Creates a default instance of the URL cache |
|
| Method Summary | |
|---|---|
void |
clearCache()
Removes all cached files from the cache directory. |
void |
clearOldCache()
Removes all obsolete cached files from the cache directory that do not match the latest revision. |
java.io.File |
getCacheRoot()
|
long |
getCurrentSize()
Computes the size of the cached files. |
DownloadCache.Strategy |
getStrategy()
|
protected java.io.File |
initCacheRoot()
Returns the directory to be used as a cache. |
java.io.InputStream |
openCachedUrl(java.lang.String urlString,
ITaskMonitor monitor)
Downloads a small file, typically XML manifests. |
com.android.utils.Pair<java.io.InputStream,org.apache.http.HttpResponse> |
openDirectUrl(java.lang.String urlString,
org.apache.http.Header[] headers,
ITaskMonitor monitor)
Does a direct download of the given URL using UrlOpener. |
com.android.utils.Pair<java.io.InputStream,java.lang.Integer> |
openDirectUrl(java.lang.String urlString,
ITaskMonitor monitor)
This is a simplified convenience method that calls openDirectUrl(String, Header[], ITaskMonitor)
without passing any specific HTTP headers and returns the resulting input stream
and the HTTP status code. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public DownloadCache(DownloadCache.Strategy strategy)
| Method Detail |
|---|
public DownloadCache.Strategy getStrategy()
public java.io.File getCacheRoot()
public long getCurrentSize()
public void clearCache()
public void clearOldCache()
protected java.io.File initCacheRoot()
public com.android.utils.Pair<java.io.InputStream,org.apache.http.HttpResponse> openDirectUrl(@NonNull
java.lang.String urlString,
@Nullable
org.apache.http.Header[] headers,
@NonNull
ITaskMonitor monitor)
throws java.io.IOException,
CanceledByUserException
UrlOpener.
This does not check the download cache and does not attempt to cache the file.
Instead the HttpClient library returns a progressive download stream.
For details on realm authentication and user/password handling,
check the underlying UrlOpener.openUrl(String, boolean, ITaskMonitor, Header[])
documentation.
The resulting input stream may not support mark/reset.
urlString - the URL string to be opened.headers - An optional set of headers to pass when requesting the resource. Can be null.monitor - ITaskMonitor which is related to this URL
fetching.
InputStream and an HttpResponse.
The pair is never null.
The input stream can be null in case of error, although in general the
method will probably throw an exception instead.
The caller should look at the response code's status and only accept the
input stream if it's the desired code (e.g. 200 or 206).
java.io.IOException - Exception thrown when there are problems retrieving
the URL or its content.
CanceledByUserException - Exception thrown if the user cancels the
authentication dialog.
public com.android.utils.Pair<java.io.InputStream,java.lang.Integer> openDirectUrl(@NonNull
java.lang.String urlString,
@NonNull
ITaskMonitor monitor)
throws java.io.IOException,
CanceledByUserException
openDirectUrl(String, Header[], ITaskMonitor)
without passing any specific HTTP headers and returns the resulting input stream
and the HTTP status code.
See the original method's description for details on its behavior.
openDirectUrl(String, Header[], ITaskMonitor) can accept customized
HTTP headers to send with the requests and also returns the full HTTP
response -- status line with code and protocol and all headers.
The resulting input stream may not support mark/reset.
urlString - the URL string to be opened.monitor - ITaskMonitor which is related to this URL
fetching.
InputStream and an HTTP status code.
The pair is never null.
The input stream can be null in case of error, although in general the
method will probably throw an exception instead.
The caller should look at the response code's status and only accept the
input stream if it's the desired code (e.g. 200 or 206).
java.io.IOException - Exception thrown when there are problems retrieving
the URL or its content.
CanceledByUserException - Exception thrown if the user cancels the
authentication dialog.openDirectUrl(String, Header[], ITaskMonitor)
public java.io.InputStream openCachedUrl(java.lang.String urlString,
ITaskMonitor monitor)
throws java.io.IOException,
CanceledByUserException
DownloadCache.Strategy governs whether the file is served as-is
from the cache, potentially updated first or directly downloaded.
For large downloads (e.g. installable archives) please do not invoke the
cache and instead use the openDirectUrl(java.lang.String, org.apache.http.Header[], com.android.sdklib.internal.repository.ITaskMonitor) method.
For details on realm authentication and user/password handling,
check the underlying UrlOpener.openUrl(String, boolean, ITaskMonitor, Header[])
documentation.
urlString - the URL string to be opened.monitor - ITaskMonitor which is related to this URL
fetching.
InputStream holding the URL content.
Returns null if there's no content (e.g. resource not found.)
Returns null if the document is not cached and strategy is DownloadCache.Strategy.ONLY_CACHE.
java.io.IOException - Exception thrown when there are problems retrieving
the URL or its content.
CanceledByUserException - Exception thrown if the user cancels the
authentication dialog.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||