Java Byte Array from getBytesFromObject(Serializable obj)

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

Description

get Bytes From Object

License

Apache License

Declaration

public static byte[] getBytesFromObject(Serializable obj)
            throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;

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

public class Main {
    public static byte[] getBytesFromObject(Serializable obj)
            throws Exception {
        if (obj == null) {
            return null;
        }/*from  ww w .  j a v  a  2 s.c o  m*/
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bo);
        oos.writeObject(obj);
        return bo.toByteArray();
    }
}

Related

  1. getBytesFromHexaText(String text)
  2. getBytesFromImage(File file)
  3. getBytesFromInt(int value)
  4. getBytesFromList(List values)
  5. getBytesFromObject(Serializable data)
  6. getBytesFromResource(String resource)
  7. getBytesFromStream(int length, ByteArrayInputStream bais)
  8. getBytesFromString(final String str, final int length, final String coding)
  9. getBytesFromText(String text, String charset)

  10. HOME | Copyright © www.java2s.com 2016