Android Open Source - GenDbHandler Converter






From Project

Back to project page GenDbHandler.

License

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.

Java Source Code

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
            }
        }
    }
}




Java Source Code List

net.cattaka.util.genasyncif.AsyncIfAttr.java
net.cattaka.util.genasyncif.AsyncInterfaceException.java
net.cattaka.util.genasyncif.GenAsyncInterface.java
net.cattaka.util.genasyncif.apt.GenAsycInterfaceAnnotationProcessor.java
net.cattaka.util.gendbhandler.Accessor.java
net.cattaka.util.gendbhandler.Attribute.java
net.cattaka.util.gendbhandler.GenDbHandler.java
net.cattaka.util.gendbhandler.apt.Bug300408.java
net.cattaka.util.gendbhandler.apt.Converter.java
net.cattaka.util.gendbhandler.apt.GenDbHandlerAnnotationProcessor.java
net.cattaka.util.gendbhandler.apt.InnerFieldType.java
net.cattaka.util.genparcelfunc.GenParcelFuncAnnotationProcessorFactory.java
net.cattaka.util.genparcelfunc.GenParcelFuncAnnotationProcessor.java
net.cattaka.util.genparcelfunc.GenParcelFuncPlugin.java
net.cattaka.util.genparcelfunc.GenParcelFunc.java
net.cattaka.util.genparcelfunc.ParcelFuncAttr.java