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


Java CacheHeader类代码示例

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


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

示例1: cacheHeaderSerialization

import com.android.volley.toolbox.DiskBasedCache.CacheHeader; //导入依赖的package包/类
@Test public void cacheHeaderSerialization() throws Exception {
    Cache.Entry e = new Cache.Entry();
    e.data = new byte[8];
    e.serverDate = 1234567L;
    e.lastModified = 13572468L;
    e.ttl = 9876543L;
    e.softTtl = 8765432L;
    e.etag = "etag";
    e.responseHeaders = new HashMap<String, String>();
    e.responseHeaders.put("fruit", "banana");

    CacheHeader first = new CacheHeader("my-magical-key", e);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    first.writeHeader(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CacheHeader second = CacheHeader.readHeader(bais);

    assertEquals(first.key, second.key);
    assertEquals(first.serverDate, second.serverDate);
    assertEquals(first.lastModified, second.lastModified);
    assertEquals(first.ttl, second.ttl);
    assertEquals(first.softTtl, second.softTtl);
    assertEquals(first.etag, second.etag);
    assertEquals(first.responseHeaders, second.responseHeaders);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:DiskBasedCacheTest.java

示例2: testCacheHeaderSerialization

import com.android.volley.toolbox.DiskBasedCache.CacheHeader; //导入依赖的package包/类
public void testCacheHeaderSerialization() throws Exception {
    Cache.Entry e = new Cache.Entry();
    e.data = new byte[8];
    e.serverDate = 1234567L;
    e.ttl = 9876543L;
    e.softTtl = 8765432L;
    e.etag = "etag";
    e.responseHeaders = new HashMap<String, String>();
    e.responseHeaders.put("fruit", "banana");

    CacheHeader first = new CacheHeader("my-magical-key", e);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    first.writeHeader(baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CacheHeader second = CacheHeader.readHeader(bais);

    assertEquals(first.key, second.key);
    assertEquals(first.serverDate, second.serverDate);
    assertEquals(first.ttl, second.ttl);
    assertEquals(first.softTtl, second.softTtl);
    assertEquals(first.etag, second.etag);
    assertEquals(first.responseHeaders, second.responseHeaders);
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:24,代码来源:DiskBasedCacheTest.java

示例3: testCacheHeaderSerializationOldToNewFormat

import com.android.volley.toolbox.DiskBasedCache.CacheHeader; //导入依赖的package包/类
/** deserializing the old format into the new one. */
@Test public void testCacheHeaderSerializationOldToNewFormat() throws Exception {

    final int CACHE_MAGIC = 0x20140623;
    final String key = "key";
    final String etag = "etag";
    final long serverDate = 1234567890l;
    final long ttl = 1357924680l;
    final long softTtl = 2468013579l;

    Map<String, String> responseHeaders = new HashMap<String, String>();
    responseHeaders.put("first", "thing");
    responseHeaders.put("second", "item");

    // write old sytle header (without lastModified)
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DiskBasedCache.writeInt(baos, CACHE_MAGIC);
    DiskBasedCache.writeString(baos, key);
    DiskBasedCache.writeString(baos, etag == null ? "" : etag);
    DiskBasedCache.writeLong(baos, serverDate);
    DiskBasedCache.writeLong(baos, ttl);
    DiskBasedCache.writeLong(baos, softTtl);
    DiskBasedCache.writeStringStringMap(responseHeaders, baos);

    // read / test new style header (with lastModified)
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CacheHeader cacheHeader = CacheHeader.readHeader(bais);

    assertEquals(cacheHeader.key, key);
    assertEquals(cacheHeader.etag, etag);
    assertEquals(cacheHeader.serverDate, serverDate);
    assertEquals(cacheHeader.ttl, ttl);
    assertEquals(cacheHeader.softTtl, softTtl);
    assertEquals(cacheHeader.responseHeaders, responseHeaders);

    // the old format doesn't know lastModified
    assertEquals(cacheHeader.lastModified, 0);
}
 
开发者ID:spark3dp,项目名称:spark-android-SDK,代码行数:39,代码来源:DiskBasedCacheTest.java


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