Here you can find the source of serialize(Object object, boolean zipped)
Parameter | Description |
---|---|
object | to serialize |
zipped | or not |
Parameter | Description |
---|---|
IOException | the iO exception |
public static byte[] serialize(Object object, boolean zipped) throws IOException
//package com.java2s; /*//from ww w . j a v a2 s. com * Copyright (c) 2005-2016 Vincent Vandenschrick. All rights reserved. * * This file is part of the Jspresso framework. * * Jspresso 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. * * Jspresso 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 Jspresso. If not, see <http://www.gnu.org/licenses/>. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.zip.GZIPOutputStream; public class Main { /** * Serialize one object. * * @param object to serialize * @param zipped or not * @return the serialized object * @throws IOException the iO exception */ public static byte[] serialize(Object object, boolean zipped) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream oo; if (zipped) { oo = new ObjectOutputStream(new GZIPOutputStream(bo)); } else { oo = new ObjectOutputStream(bo); } oo.writeObject(object); oo.close(); return bo.toByteArray(); } }