Back to project page GenDbHandler.
The source code is released under:
Open Data Commons ? Public Domain Dedication & Licence (PDDL) Preamble The Open Data Commons ? Public Domain Dedication & Licence is a document intended to allow you to freely share, modify, an...
If you think the Android project GenDbHandler 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 net.cattaka.util.gendbhandler.apt; /*from w ww .j ava 2 s .c o m*/ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; public abstract class Converter<F, T> { public abstract T encode(F src); public abstract F decode(T src); public static byte[] toByteArray(Serializable src) { if (src == null) { return null; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(src); out.flush(); return bos.toByteArray(); } catch (IOException ex) { // ignore close exception return null; } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { // ignore close exception } try { bos.close(); } catch (IOException ex) { // ignore close exception } } } public static <T> T fromByteArray(byte[] src) { if (src == null) { return null; } ByteArrayInputStream bis = new ByteArrayInputStream(src); ObjectInput in = null; try { in = new ObjectInputStream(bis); @SuppressWarnings("unchecked") T obj = (T)in.readObject(); return obj; } catch (ClassNotFoundException ex) { // ignore close exception return null; } catch (IOException ex) { // ignore close exception return null; } finally { try { if (in != null) { in.close(); } } catch (IOException ex) { // ignore close exception } try { bis.close(); } catch (IOException ex) { // ignore close exception } } } }