Here you can find the source of serialize(Serializable serializable)
Parameter | Description |
---|---|
serializable | is the Serializable Object to serialize. |
serializable
as byte-array.
public static byte[] serialize(Serializable serializable)
//package com.java2s; /* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 * http://www.apache.org/licenses/LICENSE-2.0 */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { /**/*from ww w . j a v a 2 s . c o m*/ * @param serializable is the {@link Serializable} {@link Object} to serialize. * @return the given <code>serializable</code> as byte-array. */ public static byte[] serialize(Serializable serializable) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(serializable); oos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException("Failed to serialize!", e); } } }