diff --git a/src/main/java/com/github/droidfu/cachefu/AbstractCache.java b/src/main/java/com/github/droidfu/cachefu/AbstractCache.java index 9c41248..2cd21cf 100755 --- a/src/main/java/com/github/droidfu/cachefu/AbstractCache.java +++ b/src/main/java/com/github/droidfu/cachefu/AbstractCache.java @@ -57,6 +57,7 @@ public abstract class AbstractCache implements Map { public static final int DISK_CACHE_INTERNAL = 0; public static final int DISK_CACHE_SDCARD = 1; + private static final String LOG_TAG = "Droid-Fu[CacheFu]"; @@ -69,6 +70,8 @@ public abstract class AbstractCache implements Map { private String name; private long expirationInMinutes; + + public static final int DEFAULT_BUFFER_SIZE = 8192; /** * Creates a new cache instance. diff --git a/src/main/java/com/github/droidfu/cachefu/HttpResponseCache.java b/src/main/java/com/github/droidfu/cachefu/HttpResponseCache.java index 68ae395..09b0132 100644 --- a/src/main/java/com/github/droidfu/cachefu/HttpResponseCache.java +++ b/src/main/java/com/github/droidfu/cachefu/HttpResponseCache.java @@ -34,7 +34,7 @@ public String getFileNameForKey(String url) { @Override protected ResponseData readValueFromDisk(File file) throws IOException { - BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file)); + BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file),AbstractCache.DEFAULT_BUFFER_SIZE); long fileSize = file.length(); if (fileSize > Integer.MAX_VALUE) { throw new IOException("Cannot read files larger than " + Integer.MAX_VALUE + " bytes"); @@ -55,7 +55,7 @@ protected ResponseData readValueFromDisk(File file) throws IOException { @Override protected void writeValueToDisk(File file, ResponseData data) throws IOException { - BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(file)); + BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(file),AbstractCache.DEFAULT_BUFFER_SIZE); ostream.write(data.getStatusCode()); ostream.write(data.getResponseBody()); diff --git a/src/main/java/com/github/droidfu/cachefu/ImageCache.java b/src/main/java/com/github/droidfu/cachefu/ImageCache.java index 4a2f641..684d7c5 100755 --- a/src/main/java/com/github/droidfu/cachefu/ImageCache.java +++ b/src/main/java/com/github/droidfu/cachefu/ImageCache.java @@ -33,6 +33,7 @@ * */ public class ImageCache extends AbstractCache { + public ImageCache(int initialCapacity, long expirationInMinutes, int maxConcurrentThreads) { super("ImageCache", initialCapacity, expirationInMinutes, maxConcurrentThreads); @@ -49,7 +50,7 @@ public String getFileNameForKey(String imageUrl) { @Override protected byte[] readValueFromDisk(File file) throws IOException { - BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file)); + BufferedInputStream istream = new BufferedInputStream(new FileInputStream(file),AbstractCache.DEFAULT_BUFFER_SIZE); long fileSize = file.length(); if (fileSize > Integer.MAX_VALUE) { throw new IOException("Cannot read files larger than " + Integer.MAX_VALUE + " bytes"); @@ -74,7 +75,7 @@ public synchronized Bitmap getBitmap(Object elementKey) { @Override protected void writeValueToDisk(File file, byte[] imageData) throws IOException { - BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(file)); + BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(file),AbstractCache.DEFAULT_BUFFER_SIZE); ostream.write(imageData); diff --git a/src/main/java/com/github/droidfu/cachefu/ModelCache.java b/src/main/java/com/github/droidfu/cachefu/ModelCache.java index c6dcae4..8aef158 100644 --- a/src/main/java/com/github/droidfu/cachefu/ModelCache.java +++ b/src/main/java/com/github/droidfu/cachefu/ModelCache.java @@ -68,7 +68,7 @@ protected CachedModel readValueFromDisk(File file) throws IOException { // Read file into byte array byte[] dataWritten = new byte[(int) file.length()]; - BufferedInputStream bistream = new BufferedInputStream(istream); + BufferedInputStream bistream = new BufferedInputStream(istream,AbstractCache.DEFAULT_BUFFER_SIZE); bistream.read(dataWritten); bistream.close(); @@ -105,7 +105,7 @@ protected void writeValueToDisk(File file, CachedModel data) throws IOException // Write byte data to file FileOutputStream ostream = new FileOutputStream(file); - BufferedOutputStream bistream = new BufferedOutputStream(ostream); + BufferedOutputStream bistream = new BufferedOutputStream(ostream,AbstractCache.DEFAULT_BUFFER_SIZE); bistream.write(parcelOut.marshall()); } diff --git a/src/main/java/com/github/droidfu/imageloader/ImageLoader.java b/src/main/java/com/github/droidfu/imageloader/ImageLoader.java index 901d4ca..ff16c54 100755 --- a/src/main/java/com/github/droidfu/imageloader/ImageLoader.java +++ b/src/main/java/com/github/droidfu/imageloader/ImageLoader.java @@ -100,6 +100,16 @@ public static synchronized void initialize(Context context) { imageCache.enableDiskCache(context, ImageCache.DISK_CACHE_SDCARD); } } + + public static synchronized void initialize(Context context, boolean enableSDCardCache) { + if (executor == null) { + executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(DEFAULT_POOL_SIZE); + } + if (imageCache == null) { + imageCache = new ImageCache(25, expirationInMinutes, DEFAULT_POOL_SIZE); + imageCache.enableDiskCache(context, (enableSDCardCache) ? ImageCache.DISK_CACHE_SDCARD:ImageCache.DISK_CACHE_INTERNAL); + } + } public static synchronized void initialize(Context context, long expirationInMinutes) { ImageLoader.expirationInMinutes = expirationInMinutes; diff --git a/src/main/java/com/google/common/base/FinalizableReferenceQueue.java b/src/main/java/com/google/common/base/FinalizableReferenceQueue.java index 531ba0d..758aad9 100644 --- a/src/main/java/com/google/common/base/FinalizableReferenceQueue.java +++ b/src/main/java/com/google/common/base/FinalizableReferenceQueue.java @@ -253,7 +253,7 @@ public Class loadFinalizer() { ClassLoader finalizerLoader = newLoader(getBaseUrl()); return finalizerLoader.loadClass(FINALIZER_CLASS_NAME); } catch (Exception e) { - logger.log(Level.WARNING, LOADING_ERROR, e); + //logger.log(Level.WARNING, LOADING_ERROR, e); return null; } }