Android Object Serialization obj2Bytes(Object obj)

Here you can find the source of obj2Bytes(Object obj)

Description

obj Bytes

Declaration

public static byte[] obj2Bytes(Object obj) 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.ObjectOutputStream;

public class Main {

    public static byte[] obj2Bytes(Object obj) {
        byte[] result = null;

        try {/*from   ww w.j ava2s  . c om*/
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            ObjectOutputStream oo = new ObjectOutputStream(bo);
            oo.writeObject(obj);
            result = bo.toByteArray();
            bo.close();
            oo.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return result;
    }
}

Related

  1. saveObject(Context context, String fileName, Object obj)
  2. writeObjectToFile(Object obj, String filePath)
  3. writeObjectToFile(Object obj, String filePath, boolean append)
  4. writeQueueToFile(Queue list, String filePath)
  5. ObjectToByte(Serializable obj)
  6. obj2Bytes(Object obj)
  7. objectToByte(Object obj)
  8. getObjectFormFile(String filePath)