Java Byte Array from getBytes(final Serializable obj)

Here you can find the source of getBytes(final Serializable obj)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(final Serializable obj) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;

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

public class Main {

    public static byte[] getBytes(final Serializable obj) throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {/*  www .j ava2s.c o  m*/
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            try {
                oos.writeObject(obj);
            } finally {
                oos.close();
            }
        } finally {
            bos.close();
        }
        return bos.toByteArray();
    }
}

Related

  1. getBytes(byte[] buffer, int offset)
  2. getBytes(Class clazz)
  3. getBytes(Class clazz)
  4. getBytes(Class cls, String resourceName)
  5. getBytes(final InputStream is)
  6. getBytes(final String data, String charset)
  7. getBytes(final String data, String charset)
  8. getBytes(final String value, final String characterEncoding)
  9. getBytes(int length, InputStream inStream)