Here you can find the source of toSerialized(final Serializable src)
Parameter | Description |
---|---|
src | the instance to serialize |
public static byte[] toSerialized(final Serializable src)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { /**// w w w . ja v a 2 s .c o m * Return the serialized form of the source * * @param src * the instance to serialize * * @return bytes representing the serialized object */ public static byte[] toSerialized(final Serializable src) { if (src == null) throw new IllegalArgumentException("src null"); ByteArrayOutputStream bas = new ByteArrayOutputStream(128); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(bas); oos.writeObject(src); oos.flush(); } catch (IOException ex) { } finally { if (bas != null) try { bas.close(); } catch (IOException ignore) { // Ignore } if (oos != null) try { oos.close(); } catch (IOException ignore) { // Ignore } } return bas.toByteArray(); } }