Java Object Serialize serialize(Serializable... objects)

Here you can find the source of serialize(Serializable... objects)

Description

This method takes the given serializable arguments, serializes them into a byte[] and passes it back to the caller.

License

Open Source License

Declaration

public static final byte[] serialize(Serializable... objects) 

Method Source Code

//package com.java2s;
/*// w  w  w .j a v a 2  s . c o m
 *   Copyright 2010 The Portico Project
 *
 *   This file is part of portico.
 *
 *   portico is free software; you can redistribute it and/or modify
 *   it under the terms of the Common Developer and Distribution License (CDDL) 
 *   as published by Sun Microsystems. For more information see the LICENSE file.
 *   
 *   Use of this software is strictly AT YOUR OWN RISK!!!
 *   If something bad happens you do not have permission to come crying to me.
 *   (that goes for your lawyer as well)
 *
 */

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

import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Main {
    /**
     * This method takes the given serializable arguments, serializes them into a byte[] and
     * passes it back to the caller.
     */
    public static final byte[] serialize(Serializable... objects) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            for (Serializable temp : objects)
                oos.writeObject(temp);

            oos.close();
            return baos.toByteArray();
        } catch (IOException ioex) {
            throw new RuntimeException(ioex);
        }
    }
}

Related

  1. serialize(Serializable object)
  2. serialize(Serializable object, File dest)
  3. serialize(Serializable object, String fileName)
  4. serialize(Serializable s, File dir, String fileName)
  5. serialize(Serializable serializable)
  6. serialize(String filename, T obj)
  7. serialize(String path, String name, Object obj)
  8. serialize(T obj)
  9. serialize(T obj)