Beispiel #1
0
 @Override
 protected void writeValueToDisk(File file, Object value) throws IOException {
   if (value != null && file != null) {
     ObjectOutputStream objOutStream = null;
     FileOutputStream fos = null;
     try {
       fos = new FileOutputStream(file);
       objOutStream = new ObjectOutputStream(fos);
       objOutStream.writeObject(value);
       objOutStream.flush();
     } catch (FileNotFoundException e) {
       e.printStackTrace();
     } catch (IOException e) {
       e.printStackTrace();
     } finally {
       AppUtilLIB.closeOutputStream(objOutStream);
       AppUtilLIB.closeOutputStream(fos);
     }
   }
 }
Beispiel #2
0
 @Override
 protected Object readValueFromDisk(File file) throws IOException {
   FileInputStream ins = null;
   Object obj = null;
   ObjectInputStream objIns = null;
   try {
     ins = new FileInputStream(file);
     objIns = new ObjectInputStream(ins);
     obj = objIns.readObject();
   } catch (Exception e) {
     e.printStackTrace();
     obj = null;
   } catch (Throwable t) {
     t.printStackTrace();
     obj = null;
   } finally {
     AppUtilLIB.closeInputStream(objIns);
     AppUtilLIB.closeInputStream(ins);
   }
   return obj;
 }
Beispiel #3
0
 /** 获取图片缓存实例,如果图片缓存未创建,则创建它 */
 public static synchronized ObjectCache getInstance(Context aContext) {
   if (objectCache == null) {
     objectCache =
         new ObjectCache(
             DEFAULT_INIT_CAPACLITY,
             DEFAULT_LIVE_IN_MEMORY_MIN,
             DEFAULT_LIVE_IN_MEMORY_SEC,
             DEFAULT_THREAD_POOL_SIZE,
             ReferenceType.SOFT);
     // sdcard可用
     if (AppUtilLIB.getExternalStorageDirectory() != null) {
       objectCache.isDiskCacheEnable(aContext, DISK_CACHE_SDCARD, CACHE_DEST_NAME);
     } else {
       objectCache.isDiskCacheEnable(aContext, DISK_CACHE_UPHONE, CACHE_DEST_NAME);
     }
   }
   return objectCache;
 }