Java Object Serialize serialize(Object obj)

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

Description

Serialize an object to make an MD5 hash after call getMd5Digest Method.

License

Apache License

Parameter

Parameter Description
obj a parameter

Exception

Parameter Description
IOException an exception

Declaration

private static byte[] serialize(Object obj) throws IOException 

Method Source Code

//package com.java2s;
/**/*w  w w  . j  a  va  2  s  . co  m*/
 * Copyright (c) 2015-2017 Inria
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * <p>
 * Contributors:
 * - Christophe Gourdin <christophe.gourdin@inria.fr>
 */

import java.io.*;

public class Main {
    /**
     * Serialize an object to make an MD5 hash after call getMd5Digest Method.
     *
     * @param obj
     * @return
     * @throws IOException
     */
    private static byte[] serialize(Object obj) throws IOException {
        byte[] byteArray = null;
        ByteArrayOutputStream baos;
        ObjectOutputStream out = null;
        try {
            // These objects are closed in the finally.
            baos = new ByteArrayOutputStream();
            out = new ObjectOutputStream(baos);
            out.writeObject(obj);
            byteArray = baos.toByteArray();
        } finally {
            if (out != null) {
                out.close();
            }
        }
        return byteArray;
    }
}

Related

  1. serialize(Object o)
  2. serialize(Object o)
  3. serialize(Object obj)
  4. serialize(Object obj)
  5. serialize(Object obj)
  6. serialize(Object obj)
  7. serialize(Object obj)
  8. serialize(Object obj)
  9. serialize(Object obj)