Java Utililty Methods Object to ByteBuffer

List of utility methods to do Object to ByteBuffer

Description

The list of methods to do Object to ByteBuffer are organized into topic(s).

Method

ByteBufferserialize(Object msg)
serialize
try {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos)) {
        oos.writeObject(msg);
        oos.close();
        return ByteBuffer.wrap(bos.toByteArray());
} catch (IOException e) {
...
byte[]serialize(Object obj)
serialize
try {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(obj);
    oos.close();
    return bos.toByteArray();
} catch (IOException ioe) {
    throw new RuntimeException(ioe);
...
ByteBufferserialize(Object obj)
Serialize an object into a ByteBuffer.
try {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(obj);
    byte[] b = baos.toByteArray();
    oos.close();
    return ByteBuffer.wrap(b);
} catch (IOException e) {
...
ByteBufferserialize(Object state)
serialize
ByteArrayOutputStream bos = new ByteArrayOutputStream(512);
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
    oos.writeObject(state);
    oos.flush();
    byte[] bytes = bos.toByteArray();
    return ByteBuffer.wrap(bytes);
} catch (IOException e) {
    throw new IllegalArgumentException(e);
...
byte[]serialize(Object value)
serialize
try {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(output);
    out.writeObject(value);
    output.close();
    return output.toByteArray();
} catch (Exception e) {
    throw new RuntimeException(e);
...