当前位置: 首页>>代码示例>>Java>>正文


Java HttpResponseCache类代码示例

本文整理汇总了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;

}
 
开发者ID:nico-gonzalez,项目名称:volley-it,代码行数:28,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:flurry,项目名称:StreamAds-Android,代码行数:26,代码来源:SampleListActivity.java

示例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);
    }
}
 
开发者ID:hanscappelle,项目名称:android-rest-example,代码行数:19,代码来源:MyApplication.java

示例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);
                }
            });
}
 
开发者ID:xda,项目名称:XDA-One,代码行数:24,代码来源:RetrofitClient.java

示例5: onStop

import android.net.http.HttpResponseCache; //导入依赖的package包/类
protected void onStop() {

        HttpResponseCache cache = HttpResponseCache.getInstalled();
        if (cache != null) {
            cache.flush();
        }
    }
 
开发者ID:BlueYangDroid,项目名称:MvpPlus,代码行数:8,代码来源:MyIntentService.java

示例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();
    }
}
 
开发者ID:rishabh115,项目名称:Odyssey2017,代码行数:9,代码来源:FeedActivity.java

示例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();
    }
}
 
开发者ID:rishabh115,项目名称:Odyssey2017,代码行数:10,代码来源:FeedActivity.java

示例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();
}
 
开发者ID:yeriomin,项目名称:YalpStore,代码行数:16,代码来源:YalpStoreApplication.java

示例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);
    }
}
 
开发者ID:MobileTribe,项目名称:pandroid,代码行数:16,代码来源:NetworkUtils.java

示例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);
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-High-Performance-Programming,代码行数:11,代码来源:ResponseCache.java

示例11: onStop

import android.net.http.HttpResponseCache; //导入依赖的package包/类
protected void onStop() {
    super.onStop();
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache != null) {
        cache.flush();
    }
}
 
开发者ID:PacktPublishing,项目名称:Android-High-Performance-Programming,代码行数:8,代码来源:ResponseCache.java

示例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();
    }
}
 
开发者ID:witrisna,项目名称:android-restless,代码行数:8,代码来源:FileCache.java

示例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);
}
 
开发者ID:witrisna,项目名称:android-restless,代码行数:9,代码来源:FileCache.java

示例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();
}
 
开发者ID:crm416,项目名称:android-lite,代码行数:12,代码来源:MainActivity.java

示例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);
    }
}
 
开发者ID:crm416,项目名称:android-lite,代码行数:12,代码来源:MainActivity.java


注:本文中的android.net.http.HttpResponseCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。