private <T> T deserialize(File file, Class<T> type) { if (file == null || !file.exists()) { return null; } synchronized (serializeLock) { Input input = null; try { input = new Input(new FileInputStream(file)); return kryo.readObject(input, type); } catch (Exception e) { Logger.e(TAG, e); } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); } finally { IOUtils.closeQuietly(input); } } return null; }
@Override public void run() { synchronized (serializeLock) { File file = fileCache.create(filename); Output output = null; try { output = isHoneycomb() ? new KryoOutputHC(new FileOutputStream(file)) : new Output(new FileOutputStream(file)); kryo.writeObject(output, obj); } catch (Exception e) { Logger.e(TAG, e); } catch (OutOfMemoryError oom) { MainApplication.freeMemory(); Logger.e(TAG, oom); } finally { IOUtils.closeQuietly(output); } fileCache.put(file); } }