Java Code Examples for com.facebook.internal.FileLruCache#interceptAndPut()

The following examples show how to use com.facebook.internal.FileLruCache#interceptAndPut() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageResponseCache.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ImageResponseCache.java    From HypFacebook with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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;
}
 
Example 3
Source File: ImageResponseCache.java    From FacebookNewsfeedSample-Android with Apache License 2.0 6 votes vote down vote up
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;
}