Here you can find the source of serialize(Object obj)
Parameter | Description |
---|---|
obj | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
private static byte[] serialize(Object obj) throws IOException
//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; } }