serializable From Byte Array - Android File Input Output

Android examples for File Input Output:Object Serialization

Description

serializable From Byte Array

Demo Code


import android.content.ContentValues;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Spanned;
import android.text.TextUtils;
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 class Main{
    public static Serializable serializableFromByteArray(byte[] bytes) {
        if (bytes == null) {
            return null;
        }/*w  w  w . j av a2 s  .  co m*/
        ByteArrayInputStream bis = null;
        ObjectInput in = null;
        try {
            bis = new ByteArrayInputStream(bytes);
            in = new ObjectInputStream(bis);
            Serializable o;

            o = (Serializable) in.readObject();
            return o;
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(e);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        } finally {
            IOUtils.close(bis);
            IOUtils.close(in);
        }
    }
}

Related Tutorials