本文整理汇总了Java中android.net.http.HttpResponseCache类的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCache类的具体用法?Java HttpResponseCache怎么用?Java HttpResponseCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpResponseCache类属于android.net.http包,在下文中一共展示了HttpResponseCache类的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: onCreate
import android.net.http.HttpResponseCache; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_pane);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_toolbar);
setSupportActionBar(toolbar);
if (savedInstanceState == null) {
FragmentManager.enableDebugLogging(true);
getSupportFragmentManager().beginTransaction()
.add(R.id.container, SampleListFragment.newInstance(), SampleListFragment.TAG)
.commit();
}
// http response cache
File httpCacheDir = new File(getCacheDir(), "http");
long httpCacheSize = 100 * 1024 * 1024; // 100 MiB
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i(SampleListActivity.class.getSimpleName(), "HTTP response cache installation failed:" + e);
}
}
示例3: onCreate
import android.net.http.HttpResponseCache; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
// cookie store
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
// init cache for http responses
try {
File httpCacheDir = new File(getApplicationContext().getCacheDir(), "http");
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch(IOException e){
Log.i(TAG, "HTTP response cache installation failed:" + e);
}
}
示例4: getRestBuilder
import android.net.http.HttpResponseCache; //导入依赖的package包/类
public static RestAdapter.Builder getRestBuilder(final Context context, final String url) {
if (!sResponseCache) {
try {
final File httpCacheDir = new File(context.getCacheDir(), "http");
final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
e.printStackTrace();
}
sResponseCache = true;
}
return new RestAdapter.Builder()
.setEndpoint(url)
.setConverter(JACKSON_CONVERTER)
.setRequestInterceptor(new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
request.addHeader("Authorization",
"Basic " + XDAConstants.ENCODED_AUTHORIZATION);
}
});
}
示例5: onStop
import android.net.http.HttpResponseCache; //导入依赖的package包/类
protected void onStop() {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例6: 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();
}
}
示例7: cacher
import android.net.http.HttpResponseCache; //导入依赖的package包/类
public void cacher()
{
httpCacheDir = getExternalCacheDir();
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize); //Setting the cache
} catch (Exception e) {
e.printStackTrace();
}
}
示例8: onCreate
import android.net.http.HttpResponseCache; //导入依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
try {
HttpResponseCache.install(new File(getCacheDir(), "http"), 5 * 1024 * 1024);
} catch (IOException e) {
Log.e(getClass().getSimpleName(), "Could not register cache " + e.getMessage());
}
}
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
Thread.setDefaultUncaughtExceptionHandler(new YalpStoreUncaughtExceptionHandler(getApplicationContext()));
registerDownloadReceiver();
registerInstallReceiver();
}
示例9: enableHttpCaching
import android.net.http.HttpResponseCache; //导入依赖的package包/类
/**
* Enable caching for http request : must use HttpUrlConnection !
* see : <a href="http://developer.android.com/reference/android/net/http/HttpResponseCache.html">HttpResponseCache</a>
*
* @param context
*/
public static void enableHttpCaching(Context context) {
long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
try {
File httpCacheDir = new File(context.getCacheDir(), "http");
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i("", "HTTP response cache failed:" + e);
}
}
示例10: onCreate
import android.net.http.HttpResponseCache; //导入依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
File httpCacheDir = new File(getCacheDir(), "http");
long httpCacheSize = 0;
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (IOException e) {
Log.i(getClass().getName(), "HTTP response cache installation failed:" + e);
}
}
示例11: onStop
import android.net.http.HttpResponseCache; //导入依赖的package包/类
protected void onStop() {
super.onStop();
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例12: put
import android.net.http.HttpResponseCache; //导入依赖的package包/类
@Override
public void put(Request key, HttpResponse value) {
HttpResponseCache cache = HttpResponseCache.getInstalled();
if (cache != null) {
cache.flush();
}
}
示例13: 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);
}
示例14: 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();
}
示例15: enableHttpResponseCache
import android.net.http.HttpResponseCache; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void enableHttpResponseCache() {
final long httpCacheSize = 10 * 1024 * 1024;
final File httpCacheDir = new File(getCacheDir(), "http");
try {
HttpResponseCache.install(httpCacheDir, httpCacheSize);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}