本文整理汇总了Java中android.net.http.HttpResponseCache.getInstalled方法的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCache.getInstalled方法的具体用法?Java HttpResponseCache.getInstalled怎么用?Java HttpResponseCache.getInstalled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.http.HttpResponseCache
的用法示例。
在下文中一共展示了HttpResponseCache.getInstalled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchFromHTTPUrlConnectionCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
/**
* Fetches an entry value from the HttpResponseCache cache
* @param connection connection from which we need the cache
* @param uri uri to use to get the cache entry
* @return cache entry value as String
*/
private String fetchFromHTTPUrlConnectionCache(HttpURLConnection connection, URI uri) {
try {
HttpResponseCache responseCache = HttpResponseCache.getInstalled();
if(responseCache != null){
CacheResponse cacheResponse = responseCache.get(uri, "GET", connection.getRequestProperties());
Scanner scanner = new Scanner(cacheResponse.getBody(), "UTF-8");
StringBuilder sb = new StringBuilder();
while (scanner.hasNextLine()){
sb.append(scanner.nextLine());
}
return sb.toString();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
示例2: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
protected void onStop() {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例3: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
protected void onStop() {
super.onStop();
HttpResponseCache cache = HttpResponseCache.getInstalled();
if(cache != null) { //Clearing the cache
cache.flush();
}
}
示例4: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
protected void onStop() {
super.onStop();
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例5: put
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void put(Request key, HttpResponse value) {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例6: clear
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void clear() throws IOException {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.delete();
}
HttpResponseCache.install(file, size);
}
示例7: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
protected void onStop() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
final HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
super.onStop();
}
示例8: onPause
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
protected void onPause() {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
super.onPause();
}
示例9: invalidateCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
/**
* Invalidates both HttpResponseCache and Volley cache
* @param view
*/
public void invalidateCache(View view) {
mRequestQueue.getCache().clear();
try {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if(cache != null) cache.delete();
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this, "Cache is now empty", Toast.LENGTH_SHORT).show();
}
示例10: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
protected void onStop() {
super.onStop();
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例11: onStop
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
protected void onStop() {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
super.onStop();
}
示例12: installHttpResponseCache
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static HttpResponseCache installHttpResponseCache(final File cacheDir)
throws IOException {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) {
final long maxSize = calculateDiskCacheSize(cacheDir);
cache = HttpResponseCache.install(cacheDir, maxSize);
}
return cache;
}
示例13: install
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
static Object install(Context context) throws IOException {
File cacheDir = Utils.createDefaultCacheDir(context);
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache == null) {
long maxSize = Utils.calculateDiskCacheSize(cacheDir);
cache = HttpResponseCache.install(cacheDir, maxSize);
}
return cache;
}
示例14: installedCacheIsReturned
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Test
public void installedCacheIsReturned() throws Exception {
assertThat(HttpResponseCache.getInstalled()).isNull();
HttpResponseCache cache = HttpResponseCache.install(File.createTempFile("foo", "bar"), 42);
HttpResponseCache installed = HttpResponseCache.getInstalled();
assertThat(installed).isSameAs(cache);
assertThat(installed.maxSize()).isEqualTo(42);
}
示例15: close
import android.net.http.HttpResponseCache; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}