View Javadoc
1 /*** 2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p> 3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following 4 * conditions are met:<p> 5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the 8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written 9 * permission.<p> 10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p> 16 */ 17 18 package com.codestreet.messageforge; 19 20 import java.io.ObjectInputStream; 21 import java.io.ObjectOutputStream; 22 import java.io.InputStream; 23 import java.io.OutputStream; 24 25 /*** 26 * Converter class for MsgMap and serialized streams. 27 * @author Jawaid Hakim. 28 */ 29 public abstract class ConverterSerialization extends Converter 30 { 31 /*** 32 * Serialize a RMapMessage and create an ObjectOutputStream. 33 * @param outs Output stream used to construct the ObjectOutputStream. 34 * @param source RMapMessage to serialize. 35 * @return ObjectOutputStream with the serialized source RMapMessage. 36 */ 37 public static ObjectOutputStream marshal(OutputStream outs, RMapMessage source) throws ConverterException 38 { 39 ObjectOutputStream objOutStr = null; 40 try 41 { 42 objOutStr = new ObjectOutputStream(outs); 43 objOutStr.writeObject(source); 44 } 45 catch (java.io.IOException ex) 46 { 47 throw new ConverterException(ex); 48 } 49 return objOutStr; 50 } 51 52 /*** 53 * De-serialize a RMapMessage from an InputStream. 54 * @param ins Input stream used to construct the ObjectInputStream. 55 * @return RMapMessage de-serialized from the input stream. 56 */ 57 public static RMapMessage unmarshal(InputStream ins) throws ConverterException 58 { 59 try 60 { 61 ObjectInputStream objInStr = new ObjectInputStream(ins); 62 return (RMapMessage)objInStr.readObject(); 63 } 64 catch (java.io.IOException ex) 65 { 66 throw new ConverterException(ex); 67 } 68 catch (ClassNotFoundException ex) 69 { 70 throw new ConverterException(ex); 71 } 72 } 73 }

This page was automatically generated by Maven