1 7 package org.jboss.cache.marshall; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 import java.io.IOException ; 13 import java.io.ObjectInputStream ; 14 import java.io.ObjectOutputStream ; 15 import java.io.OutputStream ; 16 17 23 public class ObjectSerializationFactory 24 { 25 static boolean useJBossSerialization = false; 26 private static Log log = LogFactory.getLog(ObjectSerializationFactory.class); 27 static ObjectStreamFactory factory = new JavaObjectStreamFactory(); 28 29 static 30 { 31 String useJBossSerializationStr = System.getProperty("serialization.jboss", "true"); 32 useJBossSerialization = Boolean.valueOf(useJBossSerializationStr); 33 34 try 35 { 36 if (useJBossSerialization) 37 { 38 factory = (ObjectStreamFactory) Class.forName("org.jboss.cache.marshall.JBossObjectStreamFactory").newInstance(); 39 } 40 } 41 catch (Exception e) 42 { 43 log.error("Unable to load JBossObjectStreamFactory. Perhaps jboss-serialization jar not loaded?", e); 44 log.error("Falling back to java serialization."); 45 46 } 47 } 48 49 public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException 50 { 51 return factory.createObjectOutputStream(out); 52 } 53 54 public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException 55 { 56 return factory.createObjectInputStream(bytes); 57 } 58 59 public static boolean useJBossSerialization() 60 { 61 return useJBossSerialization; 62 } 63 } 64 | Popular Tags |