Java Object Serialize serialize(Object state)

Here you can find the source of serialize(Object state)

Description

serialize

License

Apache License

Declaration

public static byte[] serialize(Object state) 

Method Source Code


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

import java.io.*;

public class Main {
    public static byte[] serialize(Object state) {
        ObjectOutputStream oos = null;
        try {//w  w  w  .jav  a 2s  .  co  m
            ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
            oos = new ObjectOutputStream(bos);
            oos.writeObject(state);
            oos.flush();
            return bos.toByteArray();
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        } finally {
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException e) {
                    // eat it
                }
            }
        }
    }
}

Related

  1. serialize(Object object, File file)
  2. serialize(Object object, File file)
  3. serialize(Object object, String fileName)
  4. serialize(Object object, String path)
  5. Serialize(Object serializableObject, String filePath)
  6. serialize(Object value)
  7. serialize(Object value)
  8. serialize(S value)
  9. serialize(Serializable jobSpec)