Convert bytes to Object - Android java.io

Android examples for java.io:Serializable

Description

Convert bytes to Object

Demo Code


//package com.book2s;
import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import android.util.Log;

public class Main {
    public static final String LOGERR = "ERR";

    /**/* w  w  w  . j av a 2 s . com*/
     * Convert bytes to Object
     * @param blob
     * @return
     */
    public static Object byte2Object(byte[] blob) {
        Object obj = new Object();

        ObjectInputStream bin;
        try {
            bin = new ObjectInputStream(new ByteArrayInputStream(blob));
            obj = bin.readObject();
        } catch (IOException e) {
            Log.e(LOGERR, "Unable to convert bytes to ArrayList<String> ",
                    e);
        } catch (ClassNotFoundException e) {
            Log.e(LOGERR, "Unable to convert bytes to ArrayList<String> ",
                    e);
        }

        return obj;
    }
}

Related Tutorials