Java Object to ByteBuffer serialize(Object msg)

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

Description

serialize

License

Open Source License

Declaration

public static ByteBuffer serialize(Object msg) 

Method Source Code


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

import java.nio.*;
import java.io.*;

public class Main {
    public static ByteBuffer serialize(Object msg) {
        try {/*w w  w .j a  va2 s  .co  m*/
            try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    ObjectOutputStream oos = new ObjectOutputStream(bos)) {
                oos.writeObject(msg);
                oos.close();
                return ByteBuffer.wrap(bos.toByteArray());
            }
        } catch (IOException e) {
        }
        return null;
    }
}

Related

  1. serialize(Object obj)
  2. serialize(Object obj)
  3. serialize(Object state)
  4. serialize(Object value)