本文整理汇总了Java中com.facebook.internal.FileLruCache类的典型用法代码示例。如果您正苦于以下问题:Java FileLruCache类的具体用法?Java FileLruCache怎么用?Java FileLruCache使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileLruCache类属于com.facebook.internal包,在下文中一共展示了FileLruCache类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interceptAndCacheImageStream
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
static InputStream interceptAndCacheImageStream(Context context, HttpURLConnection connection) throws IOException {
InputStream stream = null;
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
URL url = connection.getURL();
stream = connection.getInputStream(); // Default stream in case caching fails
if (isCDNURL(url)) {
try {
FileLruCache cache = getCache(context);
// Wrap stream with a caching stream
stream = cache.interceptAndPut(
url.toString(),
new BufferedHttpInputStream(stream, connection));
} catch (IOException e) {
// Caching is best effort
}
}
}
return stream;
}
示例2: cacheUrlRedirect
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
static void cacheUrlRedirect(Context context, URL fromUrl, URL toUrl) {
if (fromUrl == null || toUrl == null) {
return;
}
OutputStream redirectStream = null;
try {
FileLruCache cache = getCache(context);
redirectStream = cache.openPutStream(fromUrl.toString(), REDIRECT_CONTENT_TAG);
redirectStream.write(toUrl.toString().getBytes());
} catch (IOException e) {
// Caching is best effort
} finally {
Utility.closeQuietly(redirectStream);
}
}
示例3: clearFileLruCache
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
public static void clearFileLruCache(final FileLruCache cache) throws InterruptedException {
// since the cache clearing happens in a separate thread, we need to wait until
// the clear is complete before we can check for the existence of the old files
synchronized (cache) {
cache.clearCache();
Settings.getExecutor().execute(new Runnable() {
@Override
public void run() {
synchronized (cache) {
cache.notifyAll();
}
}
});
cache.wait(CACHE_CLEAR_TIMEOUT);
}
// sleep a little more just to make sure all the files are deleted.
Thread.sleep(CACHE_CLEAR_TIMEOUT);
}
示例4: performFirstInitialize
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
private synchronized static void performFirstInitialize() {
if (isInitialized) {
return;
}
handler = new Handler(Looper.getMainLooper());
Context appContext = FacebookSdk.getApplicationContext();
SharedPreferences sharedPreferences = appContext.getSharedPreferences(
LIKE_ACTION_CONTROLLER_STORE,
Context.MODE_PRIVATE);
objectSuffix = sharedPreferences.getInt(LIKE_ACTION_CONTROLLER_STORE_OBJECT_SUFFIX_KEY, 1);
controllerDiskCache = new FileLruCache(TAG, new FileLruCache.Limits());
registerAccessTokenTracker();
CallbackManagerImpl.registerStaticCallback(
CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(),
new CallbackManagerImpl.Callback() {
@Override
public boolean onActivityResult(int resultCode, Intent data) {
return handleOnActivityResult(
CallbackManagerImpl.RequestCodeOffset.Like.toRequestCode(),
resultCode,
data);
}
});
isInitialized = true;
}
示例5: getCachedImageStream
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
static InputStream getCachedImageStream(URL url, Context context) {
InputStream imageStream = null;
if (url != null) {
if (isCDNURL(url)) {
try {
FileLruCache cache = getCache(context);
imageStream = cache.get(url.toString());
} catch (IOException e) {
Logger.log(LoggingBehavior.CACHE, Log.WARN, TAG, e.toString());
}
}
}
return imageStream;
}
示例6: getRedirectedUrl
import com.facebook.internal.FileLruCache; //导入依赖的package包/类
static URL getRedirectedUrl(Context context, URL url) {
if (url == null) {
return null;
}
String urlString = url.toString();
URL finalUrl = null;
InputStreamReader reader = null;
try {
InputStream stream;
FileLruCache cache = getCache(context);
boolean redirectExists = false;
while ((stream = cache.get(urlString, REDIRECT_CONTENT_TAG)) != null) {
redirectExists = true;
// Get the redirected url
reader = new InputStreamReader(stream);
char[] buffer = new char[128];
int bufferLength;
StringBuilder urlBuilder = new StringBuilder();
while ((bufferLength = reader.read(buffer, 0, buffer.length)) > 0) {
urlBuilder.append(buffer, 0, bufferLength);
}
Utility.closeQuietly(reader);
// Iterate to the next url in the redirection
urlString = urlBuilder.toString();
}
if (redirectExists) {
finalUrl = new URL(urlString);
}
} catch (MalformedURLException e) {
// caching is best effort, so ignore the exception
} catch (IOException ioe) {
} finally {
Utility.closeQuietly(reader);
}
return finalUrl;
}