Here you can find the source of serialize(final Serializable object)
Parameter | Description |
---|---|
object | The object to be serialized |
public static byte[] serialize(final Serializable object)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.Serializable; public class Main { /**// w w w.ja va 2s .co m * Serialize an object. * @param object The object to be serialized * @return the +byte[]+ containing the object * @since 5.0.0 */ public static byte[] serialize(final Serializable object) { final ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); serialize(object, outBytes); return outBytes.toByteArray(); } /** * Serialize an object. * @param object The object to be serialized * @param outputStream The stream to receive the object * @since 5.0.0 */ public static void serialize(final Serializable object, final OutputStream outputStream) { ObjectOutputStream out = null; try { out = new ObjectOutputStream(outputStream); out.writeObject(object); } catch (final IOException e) { throw new RuntimeException(e); } finally { if (out != null) { try { out.close(); } catch (final IOException e) { throw new RuntimeException(e); } } } } }