1 package org.jgroups.util; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.jgroups.ChannelException; 6 import org.jgroups.conf.ClassConfigurator; 7 8 import java.io.IOException ; 9 import java.io.ObjectOutputStream ; 10 import java.io.ObjectStreamClass ; 11 import java.io.OutputStream ; 12 13 18 public class MagicObjectOutputStream extends ObjectOutputStream { 19 static ClassConfigurator conf=null; 20 static final Log log=LogFactory.getLog(MagicObjectOutputStream.class); 21 22 23 public MagicObjectOutputStream(OutputStream out) throws IOException { 24 super(out); 25 if(conf == null) { 26 try { 27 conf=ClassConfigurator.getInstance(false); 28 } 29 catch(ChannelException e) { 30 log.error("ClassConfigurator could not be instantiated", e); 31 } 32 } 33 } 34 35 protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException { 36 int magic_num; 37 if(conf == null) { 38 super.writeInt(-1); 39 super.writeClassDescriptor(desc); 40 return; 41 } 42 magic_num=conf.getMagicNumberFromObjectStreamClass(desc); 43 super.writeInt(magic_num); 44 if(magic_num == -1) { 45 if(log.isTraceEnabled()) log.trace("could not find magic number for '" + desc.getName() + "': writing full class descriptor"); 47 super.writeClassDescriptor(desc); 48 } 49 else { 50 } 53 } 54 55 } 56 57 | Popular Tags |