Here you can find the source of serialize(Serializable o)
public static byte[] serialize(Serializable o)
//package com.java2s; /*/*from w w w .j a v a 2s. co m*/ * This file is part of SpoutPlugin. * * Copyright (c) 2011 Spout LLC <http://www.spout.org/> * SpoutPlugin is licensed under the GNU Lesser General Public License. * * SpoutPlugin is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SpoutPlugin is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { private static ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(); private static ObjectOutputStream objectOutput; public static byte[] serialize(Serializable o) { try { byteOutput.reset(); objectOutput = new ObjectOutputStream(byteOutput); objectOutput.writeObject(o); objectOutput.flush(); byteOutput.flush(); byte[] b = byteOutput.toByteArray(); return b; } catch (IOException e) { e.printStackTrace(); return null; } } }