Android Object Serialization ObjectToByte(Serializable obj)

Here you can find the source of ObjectToByte(Serializable obj)

Description

Object To Byte

Declaration

public static byte[] ObjectToByte(Serializable obj) 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    public static byte[] ObjectToByte(Serializable obj) {
        byte[] bytes = null;
        try {/*from   www  .j  a  va 2 s . c o  m*/
            // object to bytearray
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            ObjectOutputStream oo = new ObjectOutputStream(bo);
            oo.writeObject(obj);

            bytes = bo.toByteArray();

            bo.close();
            oo.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return bytes;
    }
}

Related

  1. serialize(final File file, final Object o)
  2. saveObject(Context context, String fileName, Object obj)
  3. writeObjectToFile(Object obj, String filePath)
  4. writeObjectToFile(Object obj, String filePath, boolean append)
  5. writeQueueToFile(Queue list, String filePath)
  6. obj2Bytes(Object obj)
  7. obj2Bytes(Object obj)
  8. objectToByte(Object obj)
  9. getObjectFormFile(String filePath)