Here you can find the source of serializeUnserialize(Object ob)
Parameter | Description |
---|---|
ob | the actual object we want to test |
public static Object serializeUnserialize(Object ob) throws Exception
//package com.java2s; /*/*from w w w. ja v a 2s .c o m*/ * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Nuxeo - initial API and implementation * * $Id: SerializableHelper.java 28515 2008-01-06 20:37:29Z sfermigier $ */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { /** * Serializes and unserializes back an object to test whether it is correctly * rebuilt (to be used in unit tests as sanity checks). * * @param ob the actual object we want to test * @return true if the object is serializable. */ public static Object serializeUnserialize(Object ob) throws Exception { Serializable in = (Serializable) ob; ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); ObjectOutputStream outStream = new ObjectOutputStream(byteOutStream); outStream.writeObject(in); ByteArrayInputStream byteInStream = new ByteArrayInputStream(byteOutStream.toByteArray()); ObjectInputStream inStream = new ObjectInputStream(byteInStream); return inStream.readObject(); } }