1 46 52 package org.mr.core.cmc; 53 54 import java.io.ByteArrayInputStream ; 55 import java.io.ByteArrayOutputStream ; 56 import java.io.IOException ; 57 import java.io.ObjectInputStream ; 58 import java.io.ObjectOutputStream ; 59 60 import org.apache.commons.logging.Log; 61 import org.apache.commons.logging.LogFactory; 62 63 68 public class CMCMessageTransformer { 69 private static Log log; 70 71 public static CMCMessage fromBytes(byte[] buff){ 72 log=LogFactory.getLog("CMCMessageTransformer"); 73 ByteArrayInputStream in = new ByteArrayInputStream (buff) ; 74 ObjectInputStream objIn; 75 try { 76 objIn = new ObjectInputStream (in); 77 return (CMCMessage) objIn.readObject(); 78 } catch (Exception e) { 79 if(log.isErrorEnabled()){ 80 log.error("Could not parse management message ",e); 81 } 82 return null; 83 } 84 85 } 86 87 public static byte[] toBytes(CMCMessage msg) throws IOException { 88 ByteArrayOutputStream out = new ByteArrayOutputStream (); 89 ObjectOutputStream objOut = new ObjectOutputStream (out); 90 objOut.writeObject(msg); 91 objOut.flush(); 92 return out.toByteArray(); 93 } 94 95 } 96 | Popular Tags |