當前位置: 首頁>>代碼示例>>Java>>正文


Java DiskLruCache.Snapshot方法代碼示例

本文整理匯總了Java中com.jakewharton.disklrucache.DiskLruCache.Snapshot方法的典型用法代碼示例。如果您正苦於以下問題:Java DiskLruCache.Snapshot方法的具體用法?Java DiskLruCache.Snapshot怎麽用?Java DiskLruCache.Snapshot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.jakewharton.disklrucache.DiskLruCache的用法示例。


在下文中一共展示了DiskLruCache.Snapshot方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: exist

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
static int exist(String name) {

        DiskLruCache diskLruCache = getDiskLruCache();
        if (diskLruCache == null) {
            return -1;
        }
        try {
            DiskLruCache.Snapshot snapshot = diskLruCache.get(name);
            if (snapshot == null) {
                return -1;
            }
            InputStream stream = snapshot.getInputStream(1);
            boolean hasBitmap = readBoolean(stream);
            return hasBitmap ? 1 : 0;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return -1;
    }
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:21,代碼來源:BitmapWrapper.java

示例2: cacheInStorage

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
private void cacheInStorage(long id, String articleData) {
    String key = Long.toString(id);
    if (mDiskCache != null) {
        try {
            DiskLruCache.Snapshot snapshot = mDiskCache.get(key);
            
            if (snapshot == null) {
                DiskLruCache.Editor editor = mDiskCache.edit(key);

                OutputStream out = editor.newOutputStream(0);
                out.write(articleData.getBytes());
                out.close();
                editor.commit();
            } else {
                snapshot.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:22,代碼來源:ArticleCache.java

示例3: loadCacheFromStorage

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
public String loadCacheFromStorage(long id) {
    String key = Long.toString(id);
    
    if (mDiskCache != null) {
        try {
            DiskLruCache.Snapshot snapshot = mDiskCache.get(key);
            InputStream in = snapshot.getInputStream(0);
            if (in != null) {
                BufferedInputStream bis = new BufferedInputStream(in);
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                int result = bis.read();
                while (result != -1) {
                    buf.write((byte) result);
                    result = bis.read();
                }
                return buf.toString("UTF-8");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return "";
}
 
開發者ID:nichbar,項目名稱:Aequorea,代碼行數:24,代碼來源:ArticleCache.java

示例4: fetch

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
public <T> T fetch(String key, Class<T> classOfT) {
    key = sanitizeKey(key);
    try {
        DiskLruCache.Snapshot snapshot = cache.get(key);
        if (snapshot != null) {
            String data = snapshot.getString(0);
            JsonObject entryJson = gson.fromJson(data, JsonObject.class);
            Entry entry = gson.fromJson(entryJson, Entry.class);
            if (!entry.hasExpired()) {
                JsonElement element = entryJson.get(Entry.VALUE);
                if (element.isJsonPrimitive()) {
                    return gson.fromJson(element.getAsJsonPrimitive(), classOfT);
                }
                return gson.fromJson(element.getAsJsonObject(), classOfT);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:myntra,項目名稱:ObjectCache,代碼行數:22,代碼來源:ObjectCache.java

示例5: getCachedTile

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
/**
 * Load a tile from cache.
 * Returns null if there is no corresponding cache entry or it could not be loaded.
 */
private Tile getCachedTile(String key) {
    if (mCache.isClosed()) {
        return null;
    }
    try {
        DiskLruCache.Snapshot snapshot = mCache.get(key);
        if (snapshot == null) {
            // tile is not in cache
            return null;
        }

        final byte[] data = readStreamAsByteArray(snapshot.getInputStream(INDEX_DATA));
        final int height = readStreamAsInt(snapshot.getInputStream(INDEX_HEIGHT));
        final int width = readStreamAsInt(snapshot.getInputStream(INDEX_WIDTH));
        if (data != null) {
            LOGD(TAG, "Cache hit for tile " + key);
            return new Tile(width, height, data);
        }

    } catch (IOException e) {
        // ignore error
    }
    return null;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:29,代碼來源:CachedTileProvider.java

示例6: readBitmap

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
/**
 * 讀取緩存的圖片資源
 * @param key String 緩存數據對應的文件名稱,唯一值
 * @return 返回Bitmap
 */
public Bitmap readBitmap(String key) {
    Bitmap bitmap = null;
    try {
        String cacheKey = hashKeyForDisk(key);
        DiskLruCache.Snapshot snapshot = mDiskLruCache.get(cacheKey);
        if (snapshot != null) {
            InputStream is = snapshot.getInputStream(0);
            bitmap = BitmapFactory.decodeStream(is);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return bitmap;
    }
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:21,代碼來源:DiskCacheHelper.java

示例7: get

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
@Nullable
public synchronized String get(@NonNull BaseCollectionSubscription subscription) throws IOException, JSONException, NoSuchAlgorithmException {
	if(!mEnabled)
		return null;
	String fingerprint = subscription.getFingerprint();
	DiskLruCache.Snapshot record = mCache.get(fingerprint);
	if(record != null) {
		InputStream inputstream = record.getInputStream(DEFAULT_INDEX);
		byte[] rec = StreamUtility.toByteArray(inputstream);
		String jsonValue = XorUtility.xor(rec, subscription.getAuthToken());
		Logcat.d("Reading from subscription cache. key=%s; value=%s", fingerprint, jsonValue);
		JSONArray documentIdArray = new JSONArray(jsonValue);
		JSONArray documentArray = new JSONArray();
		for(int i = 0; i < documentIdArray.length(); i++) {
			String document = getDocument(subscription, documentIdArray.optString(i));
			if(document == null) {
				return null;
			}
			documentArray.put(new JSONObject(document));
		}

		return documentArray.toString();
	}
	Logcat.d("Reading from disk subscription cache. key=%s; value=null", fingerprint);
	return null;
}
 
開發者ID:rapid-io,項目名稱:rapid-io-android,代碼行數:27,代碼來源:SubscriptionDiskCache.java

示例8: performTask

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
@Override
public Page performTask() throws Throwable {
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache == null) {
            return null;
        }
        String key = title.getIdentifier();
        DiskLruCache.Snapshot snapshot = mDiskLruCache.get(key);
        if (snapshot == null) {
            return null;
        }
        try {
            Log.d(TAG, "Reading from cache: " + title.getDisplayText());
            InputStream inputStream = new BufferedInputStream(snapshot.getInputStream(0));
            String jsonStr = readFile(inputStream);
            return new Page(new JSONObject(jsonStr));
        } finally {
            snapshot.close();
        }
    }
}
 
開發者ID:gnosygnu,項目名稱:xowa_android,代碼行數:22,代碼來源:PageCache.java

示例9: isCached

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
@Override
public boolean isCached(String cacheKey) {
    String key = generateKey(cacheKey);
    boolean isInMem = mMemCache.get(key) != null;
    boolean isInDisk = false;
    if (getDiskCache() != null) {
        try {
            DiskLruCache.Snapshot snapshot = getDiskCache().get(key);
            if (snapshot != null) {
                isInDisk = snapshot.getInputStream(0) != null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return isInMem && isInDisk;
}
 
開發者ID:HujiangTechnology,項目名稱:RestVolley,代碼行數:19,代碼來源:RestVolleyImageCache.java

示例10: get

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
public static Comment get(String key){

        try {

            if(diskLrucache==null){
                throw new IllegalStateException("»º´æ²»´æÔÚ");
            }
            DiskLruCache.Snapshot snapshot=diskLrucache.get(hashKeyForDisk(key));
            if(snapshot!=null){
                InputStream in=snapshot.getInputStream(0);
               // Bitmap bitmap=BitmapFactory.decodeStream(in);
                //return bitmap;
            }

        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;
    }
 
開發者ID:liudabao,項目名稱:Evisa,代碼行數:20,代碼來源:DiskLrucacheHelper.java

示例11: getFromCache

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
/**
 * @param request
 * @return
 * 從兩種緩存中讀取數據
 */
@Override
public ResponseBody getFromCache(Request request) {
    String cacheKey = urlToKey(request.url());
    byte[] memoryResponse = (byte[]) memoryCache.get(cacheKey);
    if (memoryResponse != null) {
        Log.d("BasicCache", "從內存讀取數據!");
        return ResponseBody.create(null, memoryResponse);
    }

    try {
        DiskLruCache.Snapshot cacheSnapshot = diskCache.get(cacheKey);
        if (cacheSnapshot != null) {
            Log.d("BasicCache", "從磁盤讀取數據!");
            return ResponseBody.create(null, cacheSnapshot.getString(0).getBytes());
        } else {
            return null;
        }
    } catch (IOException exc) {
        return null;
    }
}
 
開發者ID:xqgdmg,項目名稱:Retrofit-RxJava,代碼行數:27,代碼來源:BasicCache.java

示例12: readMetadata

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
private Map<String, Serializable> readMetadata(DiskLruCache.Snapshot snapshot)
        throws IOException {
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(new BufferedInputStream(
                snapshot.getInputStream(METADATA_IDX)));
        @SuppressWarnings("unchecked")
        Map<String, Serializable> annotations = (Map<String, Serializable>) ois.readObject();
        return annotations;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        if(ois != null)
            ois.close();
    }
}
 
開發者ID:roscrazy,項目名稱:Android-RealtimeUpdate-CleanArchitecture,代碼行數:17,代碼來源:DiskCache.java

示例13: getImage

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
@Override
public InputStream getImage(String url) {
    synchronized (CACHE_LOCK) {
        if (diskLruCache == null) {
            return null;
        }
    }

    String key = getKey(url);
    try {
        DiskLruCache.Snapshot snapshot = diskLruCache.get(key);
        return snapshot != null ? snapshot.getInputStream(0) : null;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:drunlin,項目名稱:guokr-android,代碼行數:18,代碼來源:EditorModelImpl.java

示例14: containsKey

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
public boolean containsKey( String key ) {
    boolean contained = false;
    DiskLruCache.Snapshot snapshot = null;
    try {
        snapshot = mDiskCache.get( key );
        contained = snapshot != null;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if ( snapshot != null ) {
            snapshot.close();
        }
    }

    return contained;

}
 
開發者ID:nanyi5452,項目名稱:cleanDemo,代碼行數:18,代碼來源:DiskLruImageCache.java

示例15: get

import com.jakewharton.disklrucache.DiskLruCache; //導入方法依賴的package包/類
public static Bitmap get(String key){

		try {
			
			if(diskLrucache==null){
				throw new IllegalStateException("���治����");
			}
			DiskLruCache.Snapshot snapshot=diskLrucache.get(hashKeyForDisk(key));
			if(snapshot!=null){
				InputStream in=snapshot.getInputStream(0);
				Bitmap bitmap=BitmapFactory.decodeStream(in);
				return bitmap;
			}
		    
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}
 
開發者ID:liudabao,項目名稱:ImageLoadDemo,代碼行數:20,代碼來源:DiskLrucacheHelper.java


注:本文中的com.jakewharton.disklrucache.DiskLruCache.Snapshot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。