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