Java 类com.squareup.okhttp.HttpResponseCache 实例源码

项目:platform_external_okhttp    文件:Crawler.java   
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);
}
项目:open    文件:MapFragmentTest.java   
@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);
}
项目:open    文件:MapFragmentTest.java   
@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");
}
项目:platform_external_okhttp    文件:HttpResponseCacheTest.java   
@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);
}
项目:platform_external_okhttp    文件:HttpOverSpdyTest.java   
@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);
}
项目:ShopAfter    文件:DataModule.java   
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;
}
项目:Nefete    文件:DataModule.java   
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;
}
项目:android-facade-example    文件:NetworkingHelper.java   
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();
    }
}
项目:open    文件:StyleDownLoader.java   
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());
    }
}
项目:vtm    文件:OkHttpEngineTest.java   
@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);
}
项目:android-couchpotato    文件:DataModule.java   
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;
}
项目:mirrored-okhttp    文件:HttpResponseCacheTest.java   
@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);
}
项目:mirrored-okhttp    文件:HttpOverSpdyTest.java   
@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);
}
项目:callerid-for-android    文件:CallerIDApplication.java   
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");
    }
}
项目:GifDrawable    文件:DemoActivity.java   
@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();
        }
    });
}
项目:platform_external_okhttp    文件:URLConnectionTest.java   
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);
}
项目:vtm    文件:OkHttpEngine.java   
public OkHttpFactory(HttpResponseCache responseCache) {
    mClient = new OkHttpClient();
    mClient.setResponseCache(responseCache);
}
项目:mirrored-okhttp    文件:URLConnectionTest.java   
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.setResponseCache(cache);
}