Java Object Serialize Serialize(Object object)

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

Description

Serialize a object

License

Creative Commons License

Parameter

Parameter Description
object Object to be serialize

Exception

Parameter Description
IOException an exception

Return

object as serialize byte array

Declaration

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

Method Source Code


//package com.java2s;
/* //from   w  w w .j  av  a  2s  .  c o  m
 * Created: 12/05/2014
 * Author: Luke Salisbury <luke.salisbury@live.vu.edu.au>
 * Student Number: 1510439
 * Course: Programming for Networks 
 * Subject: ECB2123
 * License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 
 * License URL: http://creativecommons.org/licenses/by-nc-sa/4.0/
 *
 * Implement a Tutoring System that would register tutors interested in 
 * helping students
 */

import java.io.*;

public class Main {
    /**
     * Serialize a object 
     * @param object Object to be serialize
     * @return object as serialize byte array
     * @throws IOException
     */
    public static byte[] Serialize(Object object) throws IOException {
        ByteArrayOutputStream byteStream;
        ObjectOutput output;
        byte[] objectBytes;

        byteStream = new ByteArrayOutputStream();

        output = new ObjectOutputStream(byteStream);
        output.writeObject(object);
        output.close();

        objectBytes = byteStream.toByteArray();

        return objectBytes;
    }
}

Related

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