public Object deserialize(String fileName) throws IOException { File file = new File(Config.getResponesCacheDir(), EncryptUtil.MD5(fileName)); if (!file.exists()) { return null; } ObjectInputStream in = null; try { in = new ObjectInputStream(new FileInputStream(file)); Object o = in.readObject(); in.close(); return o; } catch (FileNotFoundException e) { throw new RuntimeException("FileNotFoundException occurred. ", e); } catch (ClassNotFoundException e) { throw new RuntimeException("ClassNotFoundException occurred. ", e); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (in != null) { try { in.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
public void serialize(String fileName, Object object) throws IOException { File file = new File(Config.getResponesCacheDir(), EncryptUtil.MD5(fileName)); if (!file.exists()) { if (!file.getParentFile().exists()) file.mkdirs(); } else { file.delete(); } file.createNewFile(); ObjectOutputStream out = null; try { out = new ObjectOutputStream(new FileOutputStream(file)); out.writeObject(object); out.close(); } catch (FileNotFoundException e) { throw new RuntimeException("FileNotFoundException occurred. ", e); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (out != null) { try { out.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }