Java Object Serialize serialize(final Object object)

Here you can find the source of serialize(final Object object)

Description

serialize

License

Open Source License

Declaration

public static final synchronized Byte[] serialize(final Object object) throws IOException 

Method Source Code

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

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    public static final synchronized Byte[] serialize(final Object object) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(object);
        return toComposite(byteArrayOutputStream.toByteArray());
    }//from   ww  w. j a  v  a2 s  .  co  m

    public static final synchronized Byte[] toComposite(final byte[] bytes) {
        Byte[] compositeBytes = new Byte[bytes.length];
        for (int i = 0; i < bytes.length; i++) {
            compositeBytes[i] = bytes[i];
        }
        return compositeBytes;
    }
}

Related

  1. serialize(@Nullable final Object obj)
  2. serialize(@Nullable Object value)
  3. serialize(File outFile, Object source)
  4. serialize(final @Nonnull Object obj)
  5. serialize(final File file, final Object o)
  6. serialize(final Object object, final File file)
  7. serialize(final Serializable obj)
  8. serialize(final Serializable object)
  9. serialize(final String path, final Object object)