|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ObjectSerializationFactory.java | - | 100% | 100% | 100% |
|
1 | /* | |
2 | * JBoss, Home of Professional Open Source | |
3 | * | |
4 | * Distributable under LGPL license. | |
5 | * See terms of license at gnu.org. | |
6 | */ | |
7 | package org.jboss.cache.marshall; | |
8 | ||
9 | import java.io.IOException; | |
10 | import java.io.InputStream; | |
11 | import java.io.ObjectInputStream; | |
12 | import java.io.ObjectOutputStream; | |
13 | import java.io.OutputStream; | |
14 | ||
15 | /** | |
16 | * Factory class for creating object output and inut streams, to allow for multiple mechanisms of serialization. | |
17 | * Java serialization is the only supported mechanism at this point. | |
18 | * | |
19 | * @author <a href="mailto:manik@jboss.org">Manik Surtani (manik@jboss.org)</a> | |
20 | * @author <a href="mailto:clebert.suconic@jboss.org">Clebert Suconic</a> | |
21 | * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a> | |
22 | */ | |
23 | public class ObjectSerializationFactory | |
24 | { | |
25 | static ObjectStreamFactory factory = new JavaObjectStreamFactory(); | |
26 | ||
27 | /* | |
28 | static | |
29 | { | |
30 | // start with the NEW property | |
31 | String propString = System.getProperty("jboss.serialization"); | |
32 | if (propString == null) | |
33 | { | |
34 | // and now check legacy | |
35 | propString = System.getProperty("serialization.jboss"); | |
36 | if (propString != null) | |
37 | log.info("The system property 'serialization.jboss' is deprecated and may be removed from future releases. Please use 'jboss.serialization' instead."); | |
38 | } | |
39 | useJBossSerialization = false; // default. | |
40 | if (propString != null) useJBossSerialization = Boolean.valueOf(propString); | |
41 | ||
42 | try | |
43 | { | |
44 | if (useJBossSerialization) | |
45 | { | |
46 | factory = (ObjectStreamFactory) Class.forName("org.jboss.cache.marshall.JBossObjectStreamFactory").newInstance(); | |
47 | } | |
48 | } | |
49 | catch (Exception e) | |
50 | { | |
51 | log.error("Unable to load JBossObjectStreamFactory. Perhaps jboss-serialization jar not loaded?", e); | |
52 | log.error("Falling back to java serialization."); | |
53 | } | |
54 | } | |
55 | */ | |
56 | ||
57 | 359629 | public static ObjectOutputStream createObjectOutputStream(OutputStream out) throws IOException |
58 | { | |
59 | 359627 | return factory.createObjectOutputStream(out); |
60 | } | |
61 | ||
62 | 327158 | public static ObjectInputStream createObjectInputStream(byte[] bytes) throws IOException |
63 | { | |
64 | 327158 | return factory.createObjectInputStream(bytes); |
65 | } | |
66 | ||
67 | 36187 | public static ObjectInputStream createObjectInputStream(InputStream in) throws IOException |
68 | { | |
69 | 36187 | return factory.createObjectInputStream(in); |
70 | } | |
71 | ||
72 | // public static boolean useJBossSerialization() | |
73 | // { | |
74 | // return useJBossSerialization; | |
75 | // } | |
76 | } |
|