Java Object Serialize serialize(Serializable obj)

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

Description

serialize

License

Apache License

Declaration

public static byte[] serialize(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[] serialize(Serializable obj) throws Exception {
        ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
        ObjectOutputStream output = new ObjectOutputStream(byteOutput);
        output.writeObject(obj);//w w  w  .j  a  v a  2 s  .  c o  m
        byte[] bytes = byteOutput.toByteArray();
        byteOutput.close();
        output.close();
        return bytes;
    }
}

Related

  1. serialize(Object value)
  2. serialize(Object value)
  3. serialize(S value)
  4. serialize(Serializable jobSpec)
  5. serialize(Serializable o)
  6. serialize(Serializable obj)
  7. serialize(Serializable obj)
  8. serialize(Serializable obj)
  9. serialize(Serializable obj, String fileName)