Example #1
0
 public void clearImageData(MediaPath path, long timeModified, int type) {
   byte[] key = makeKey(path, timeModified, type);
   long cacheKey = Utils.crc64Long(key);
   synchronized (mCache) {
     try {
       mCache.clearEntry(cacheKey);
     } catch (IOException ex) {
       // ignore.
     }
   }
 }
Example #2
0
 public void putImageData(MediaPath path, long timeModified, int type, byte[] value) {
   byte[] key = makeKey(path, timeModified, type);
   long cacheKey = Utils.crc64Long(key);
   ByteBuffer buffer = ByteBuffer.allocate(key.length + value.length);
   buffer.put(key);
   buffer.put(value);
   synchronized (mCache) {
     try {
       mCache.insert(cacheKey, buffer.array());
     } catch (IOException ex) {
       // ignore.
     }
   }
 }
Example #3
0
 /**
  * Gets the cached image data for the given <code>path</code>, <code>timeModified</code> and
  * <code>type</code>.
  *
  * <p>The image data will be stored in <code>buffer.data</code>, started from <code>buffer.offset
  * </code> for <code>buffer.length</code> bytes. If the buffer.data is not big enough, a new byte
  * array will be allocated and returned.
  *
  * @return true if the image data is found; false if not found.
  */
 public boolean getImageData(MediaPath path, long timeModified, int type, BytesBuffer buffer) {
   byte[] key = makeKey(path, timeModified, type);
   long cacheKey = Utils.crc64Long(key);
   try {
     LookupRequest request = new LookupRequest();
     request.key = cacheKey;
     request.buffer = buffer.data;
     synchronized (mCache) {
       if (!mCache.lookup(request)) return false;
     }
     if (isSameKey(key, request.buffer)) {
       buffer.data = request.buffer;
       buffer.offset = key.length;
       buffer.length = request.length - buffer.offset;
       return true;
     }
   } catch (IOException ex) {
     // ignore.
   }
   return false;
 }