Java Object Serialize serialize(java.io.Serializable obj)

Here you can find the source of serialize(java.io.Serializable obj)

Description

Serializes an object

License

Open Source License

Parameter

Parameter Description
obj a parameter

Declaration

public static byte[] serialize(java.io.Serializable obj) 

Method Source Code

//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);
        }
    }
}

Related

  1. serialize(final Object object, final File file)
  2. serialize(final Serializable obj)
  3. serialize(final Serializable object)
  4. serialize(final String path, final Object object)
  5. serialize(final String pFilename, final T pObject)
  6. serialize(Object c, ScriptableObject scope)
  7. serialize(Object o)
  8. serialize(Object o)
  9. serialize(Object obj)