本文整理汇总了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);
}
示例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);
}
示例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");
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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");
}
}
示例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();
}
});
}
示例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);
}