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


Java HttpResponseCache类代码示例

本文整理汇总了Java中com.squareup.okhttp.HttpResponseCache的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseCache类的具体用法?Java HttpResponseCache怎么用?Java HttpResponseCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpResponseCache类属于com.squareup.okhttp包,在下文中一共展示了HttpResponseCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
  if (args.length != 2) {
    System.out.println("Usage: Crawler <cache dir> <root>");
    return;
  }

  int threadCount = 20;
  long cacheByteCount = 1024L * 1024L * 100L;

  OkHttpClient client = new OkHttpClient();
  HttpResponseCache httpResponseCache = new HttpResponseCache(new File(args[0]), cacheByteCount);
  client.setOkResponseCache(httpResponseCache);

  Crawler crawler = new Crawler(client);
  crawler.queue.add(new URL(args[1]));
  crawler.parallelDrainQueue(threadCount);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:18,代码来源:Crawler.java

示例2: shouldUse10MegResponseCache

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Test
public void shouldUse10MegResponseCache() throws Exception {
    Map map = mapFragment.getMap();
    TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get();
    UrlTileSource tileSource =
            (UrlTileSource) field("mTileSource").
                    ofType(TileSource.class).in(baseLayer).get();
    HttpEngine.Factory engine = field("mHttpFactory").
            ofType(HttpEngine.Factory.class).in(tileSource).get();
    OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get();

    HttpResponseCache cache =
            (HttpResponseCache) field("responseCache").
                    ofType(OkResponseCache.class).in(client).get();
    assertThat(cache.getMaxSize()).isEqualTo(MapFragment.CACHE_SIZE);
}
 
开发者ID:mapzen,项目名称:open,代码行数:17,代码来源:MapFragmentTest.java

示例3: shouldUseResponseCacheStoredOnFile

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Test
public void shouldUseResponseCacheStoredOnFile() throws Exception {
    Map map = mapFragment.getMap();
    TileLayer baseLayer = field("mBaseLayer").ofType(TileLayer.class).in(map).get();
    UrlTileSource tileSource =
            (UrlTileSource) field("mTileSource").
                    ofType(TileSource.class).in(baseLayer).get();
    HttpEngine.Factory engine = field("mHttpFactory").
            ofType(HttpEngine.Factory.class).in(tileSource).get();
    OkHttpClient client = field("mClient").ofType(OkHttpClient.class).in(engine).get();

    HttpResponseCache cache =
            (HttpResponseCache) field("responseCache").
                    ofType(OkResponseCache.class).in(client).get();
    assertThat(cache.getDirectory().getAbsolutePath()).
            isEqualTo(activity.getExternalCacheDir().getAbsolutePath() + "/tile-cache");
}
 
开发者ID:mapzen,项目名称:open,代码行数:18,代码来源:MapFragmentTest.java

示例4: setUp

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  String tmp = System.getProperty("java.io.tmpdir");
  File cacheDir = new File(tmp, "HttpCache-" + UUID.randomUUID());
  cache = new HttpResponseCache(cacheDir, Integer.MAX_VALUE);
  ResponseCache.setDefault(cache);
  CookieHandler.setDefault(cookieManager);
  server.setNpnEnabled(false);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:9,代码来源:HttpResponseCacheTest.java

示例5: setUp

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  server.useHttps(sslContext.getSocketFactory(), false);
  client.setProtocols(Arrays.asList(protocol, Protocol.HTTP_11));
  client.setSslSocketFactory(sslContext.getSocketFactory());
  client.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
  String systemTmpDir = System.getProperty("java.io.tmpdir");
  File cacheDir = new File(systemTmpDir, "HttpCache-" + protocol + "-" + UUID.randomUUID());
  cache = new HttpResponseCache(cacheDir, Integer.MAX_VALUE);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:10,代码来源:HttpOverSpdyTest.java

示例6: createOkHttpClient

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
static OkHttpClient createOkHttpClient(Application app) {
  OkHttpClient client = new OkHttpClient();

  // Install an HTTP cache in the application cache directory.
  try {
    File cacheDir = new File(app.getCacheDir(), "http");
    HttpResponseCache cache = new HttpResponseCache(cacheDir, DISK_CACHE_SIZE);
    client.setResponseCache(cache);
  } catch (IOException e) {
    Timber.e(e, "Unable to install disk cache.");
  }

  return client;
}
 
开发者ID:kamoljan,项目名称:ShopAfter,代码行数:15,代码来源:DataModule.java

示例7: setupCache

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
public void setupCache(Context context) {
    try {
        File httpCacheDirectory = new File(context.getCacheDir().getAbsolutePath(), "HttpCache");
        HttpResponseCache cache = new HttpResponseCache(httpCacheDirectory, 20 * 1024);
        client.setResponseCache(cache);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Ruenzuo,项目名称:android-facade-example,代码行数:10,代码来源:NetworkingHelper.java

示例8: init

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
private void init() {
    final File cacheDir = new File(context.getExternalCacheDir().getAbsolutePath() + "/assets");
    final int cacheSize = 1024 * 1024;
    try {
        cache = new HttpResponseCache(cacheDir, cacheSize);
        client = new OkHttpClient();
        client.setOkResponseCache(cache);
    } catch (IOException ioe) {
        Logger.e("network failed: " + ioe.toString());
    }
}
 
开发者ID:mapzen,项目名称:open,代码行数:12,代码来源:StyleDownLoader.java

示例9: create_shouldUseTileSourceCache

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Test
public void create_shouldUseTileSourceCache() throws Exception {
	cache = new HttpResponseCache(new File("tmp"), 1024);
	OSciMap4TileSource tileSource =
	        new OSciMap4TileSource(server.getUrl("/tiles/vtm").toString());
	engine = (OkHttpEngine) new OkHttpEngine.OkHttpFactory(cache).create(tileSource);
	engine.sendRequest(new Tile(1, 2, new Integer(3).byteValue()));
	engine.requestCompleted(true);
	assertThat(cache.getRequestCount()).isEqualTo(1);
}
 
开发者ID:opensciencemap,项目名称:vtm,代码行数:11,代码来源:OkHttpEngineTest.java

示例10: createOkHttpClient

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
static OkHttpClient createOkHttpClient(Application app) {
  OkHttpClient client = new OkHttpClient();

  // Install an HTTP cache in the application cache directory.
  try {
    File cacheDir = new File(app.getCacheDir(), "http");
    HttpResponseCache cache = new HttpResponseCache(cacheDir, DISK_CACHE_SIZE);
    client.setResponseCache(cache);
  } catch (IOException e) {
    Ln.e(e, "Unable to install disk cache.");
  }

  return client;
}
 
开发者ID:f2prateek,项目名称:android-couchpotato,代码行数:15,代码来源:DataModule.java

示例11: setUp

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  String tmp = System.getProperty("java.io.tmpdir");
  File cacheDir = new File(tmp, "HttpCache-" + UUID.randomUUID());
  cache = new HttpResponseCache(cacheDir, Integer.MAX_VALUE);
  ResponseCache.setDefault(cache);
  CookieHandler.setDefault(cookieManager);
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:8,代码来源:HttpResponseCacheTest.java

示例12: setUp

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Before public void setUp() throws Exception {
  client.setSslSocketFactory(sslContext.getSocketFactory());
  client.setHostnameVerifier(NULL_HOSTNAME_VERIFIER);
  String systemTmpDir = System.getProperty("java.io.tmpdir");
  File cacheDir = new File(systemTmpDir, "HttpCache-" + UUID.randomUUID());
  cache = new HttpResponseCache(cacheDir, Integer.MAX_VALUE);
}
 
开发者ID:c-ong,项目名称:mirrored-okhttp,代码行数:8,代码来源:HttpOverSpdyTest.java

示例13: installHttpHandler

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
private void installHttpHandler(long httpCacheSize, File httpCacheDir ){
    try{
        HttpResponseCache result = new HttpResponseCache(httpCacheDir, httpCacheSize);
        ResponseCache.setDefault(result);
        URL.setURLStreamHandlerFactory(new OkHttpURLStreamHandlerFactory(new OkHttpClient()));
    }catch(Exception e){
    	Ln.e(e, "Failed to set up okhttp");
    }
}
 
开发者ID:candrews,项目名称:callerid-for-android,代码行数:10,代码来源:CallerIDApplication.java

示例14: onCreate

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        client = new OkHttpClient();
        client.setResponseCache(new HttpResponseCache(getCacheDir(), MAX_CACHE_SIZE));
    } catch (IOException e) {
        e.printStackTrace();
    }

    ViewPager viewPager = new ViewPager(this);
    viewPager.setId(android.R.id.primary);
    PagerAdapter adapter = new FragmentAdapter(getSupportFragmentManager());
    viewPager.setAdapter(adapter);
    setContentView(viewPager);

    mSystemUiHider = SystemUiHider.getInstance(this, viewPager, SystemUiHider.FLAG_HIDE_NAVIGATION);
    mSystemUiHider.setup();
    mSystemUiHider
            .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
                int mShortAnimTime;

                @Override
                @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
                public void onVisibilityChange(boolean visible) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
                        if (mShortAnimTime == 0) {
                            mShortAnimTime = getResources().getInteger(
                                    android.R.integer.config_shortAnimTime);
                        }
                    }

                    if (visible) {
                        delayedHide(AUTO_HIDE_DELAY_MILLIS);
                    }
                }
            });

    viewPager.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mSystemUiHider.toggle();
        }
    });
}
 
开发者ID:veonua,项目名称:GifDrawable,代码行数:47,代码来源:DemoActivity.java

示例15: initResponseCache

import com.squareup.okhttp.HttpResponseCache; //导入依赖的package包/类
private void initResponseCache() throws IOException {
  String tmp = System.getProperty("java.io.tmpdir");
  File cacheDir = new File(tmp, "HttpCache-" + UUID.randomUUID());
  cache = new HttpResponseCache(cacheDir, Integer.MAX_VALUE);
  client.setOkResponseCache(cache);
}
 
开发者ID:xin3liang,项目名称:platform_external_okhttp,代码行数:7,代码来源:URLConnectionTest.java


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