Back to project page antigravity.
The source code is released under:
GNU General Public License
If you think the Android project antigravity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.floatboth.antigravity; /*w w w . j a v a2s. com*/ import java.io.*; import org.androidannotations.annotations.*; @EBean public class DataCache { @App AntigravityApplication app; File cacheDir; @AfterInject public void initializeCacheDir() { cacheDir = app.getCacheDir(); } public boolean set(String filename, Object data) { try { FileOutputStream file = new FileOutputStream(new File(cacheDir, filename)); BufferedOutputStream buf = new BufferedOutputStream(file); ObjectOutput output = new ObjectOutputStream(buf); try { output.writeObject(data); } finally { output.close(); } } catch (IOException e) { return false; } return true; } public Object get(String filename) { try { FileInputStream file = new FileInputStream(new File(cacheDir, filename)); BufferedInputStream buf = new BufferedInputStream(file); ObjectInput input = new ObjectInputStream(buf); Object r; try { r = input.readObject(); } catch (Exception e) { return null; } finally { input.close(); } return r; } catch (IOException e) { return null; } } public boolean delete(String filename) { return new File(cacheDir, filename).delete(); } }