Exemple #1
0
 /// <summary>
 /// 将缓存信息写入流中
 /// </summary>
 public bool WriteHeader(Stream output)
 {
     try
     {
         DiskBasedCache.WriteInt(output, DiskBasedCache.CACHE_MAGIC);
         DiskBasedCache.WriteString(output, Key);
         DiskBasedCache.WriteString(output, ETag == null ? "" : ETag);
         DiskBasedCache.WriteLong(output, ServerDate);
         DiskBasedCache.WriteLong(output, LastModified);
         DiskBasedCache.WriteLong(output, Ttl);
         DiskBasedCache.WriteLong(output, SoftTtl);
         DiskBasedCache.WriteStringStringMap(ResponseHeaders, output);
         output.Flush();
         return(true);
     }
     catch (Exception e)
     {
         VolleyLog.D("{0}", e.ToString());
         return(false);
     }
 }
Exemple #2
0
        /// <summary>
        /// 从流中读取缓存相关信息
        /// (当前只提供文件缓存所以是从文件中读取)
        /// </summary>
        public static CacheHeader ReadHeader(Stream input)
        {
            CacheHeader entry = new CacheHeader();
            int         magic = DiskBasedCache.ReadInt(input);

            if (magic != DiskBasedCache.CACHE_MAGIC)
            {
                throw new IOException();
            }
            entry.Key  = DiskBasedCache.ReadString(input);
            entry.ETag = DiskBasedCache.ReadString(input);
            if (String.IsNullOrEmpty(entry.ETag))
            {
                entry.ETag = null;
            }
            entry.ServerDate      = DiskBasedCache.ReadLong(input);
            entry.LastModified    = DiskBasedCache.ReadLong(input);
            entry.Ttl             = DiskBasedCache.ReadLong(input);
            entry.SoftTtl         = DiskBasedCache.ReadLong(input);
            entry.ResponseHeaders = DiskBasedCache.ReadStringStringMap(input);
            return(entry);
        }