Here you can find the source of serialize(java.io.Serializable obj)
Parameter | Description |
---|---|
obj | a parameter |
public static byte[] serialize(java.io.Serializable obj)
//package com.java2s; /*// w w w. j av a 2 s . c om * Copyright 05-abr-2014 ?Deme * * This file is part of 'dmLang-8.1.0'. * * 'dmLang-8.1.0' is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License. * * 'dmLang-8.1.0' 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 'dmLang-8.1.0'. If not, see <http://www.gnu.org/licenses/>. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { /** * Serializes an object * * @param obj * @return */ public static byte[] serialize(java.io.Serializable obj) { try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { new ObjectOutputStream(out).writeObject(obj); return out.toByteArray(); } catch (IOException ex) { throw new IllegalArgumentException(ex); } } }