Java Object Serialize serialize(Object object)

Here you can find the source of serialize(Object object)

Description

serialize

License

Open Source License

Declaration

public static byte[] serialize(Object object) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 EURA NOVA.//  ww w .j a  va2  s . co m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *     Aldemar Reynaga - initial API and implementation
 *     Salim Jouili - initial API and implementation
 ******************************************************************************/

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

public class Main {
    public static byte[] serialize(Object object) throws IOException {

        return convertObjectToBytes(object);
    }

    public static byte[] convertObjectToBytes(Object object) throws IOException {
        byte[] msg = null;
        ByteArrayOutputStream bos;
        ObjectOutput out = null;
        bos = new ByteArrayOutputStream();
        out = new ObjectOutputStream(bos);
        out.writeObject(object);
        out.flush();

        bos.flush();

        msg = bos.toByteArray();
        out.close();
        bos.close();
        return msg;
    }
}

Related

  1. serialize(Object obj, String fileName)
  2. serialize(Object obj, String fileName)
  3. serialize(Object obj, String fname, boolean gzipped)
  4. serialize(Object objData, Class typeOfT)
  5. Serialize(Object object)
  6. serialize(Object object)
  7. serialize(Object object)
  8. serialize(Object object)
  9. serialize(Object object)