Here you can find the source of serialize(Object object)
Parameter | Description |
---|---|
object | - object to serialize |
Parameter | Description |
---|---|
IOException | - if there is an error with serialization |
static public byte[] serialize(Object object) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /**/*from w w w . j a va2s.c o m*/ * Serialize the specified object * * @param object - object to serialize * @return byte[] - the serialized object * @throws IOException - if there is an error with serialization */ static public byte[] serialize(Object object) throws IOException { ByteArrayOutputStream bstream = new ByteArrayOutputStream(); ObjectOutputStream ostream = new ObjectOutputStream(bstream); ostream.writeObject(object); return bstream.toByteArray(); } }