KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > marshall > JBossObjectStreamFactory


1 package org.jboss.cache.marshall;
2
3 import org.jboss.serial.io.JBossObjectInputStreamSharedTree;
4 import org.jboss.serial.io.JBossObjectOutputStreamSharedTree;
5
6 import java.io.ByteArrayInputStream JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.io.ObjectInputStream JavaDoc;
10 import java.io.ObjectOutputStream JavaDoc;
11 import java.io.OutputStream JavaDoc;
12
13 /**
14  * @author Clebert Suconic
15  * @since 1.4.1
16  */

17 class JBossObjectStreamFactory implements ObjectStreamFactory
18 {
19    static class JBossObjectInputStreamOverride extends JBossObjectInputStreamSharedTree
20    {
21
22       public JBossObjectInputStreamOverride(InputStream JavaDoc input) throws IOException JavaDoc
23       {
24          super(input);
25       }
26
27       public Object JavaDoc readObjectOverride() throws IOException JavaDoc, ClassNotFoundException JavaDoc
28       {
29          ClassLoader JavaDoc older = this.getClassLoader();
30          try
31          {
32             this.setClassLoader(Thread.currentThread().getContextClassLoader());
33             return super.readObjectOverride();
34          }
35          finally
36          {
37             this.setClassLoader(older);
38          }
39       }
40
41    }
42
43
44    public ObjectInputStream JavaDoc createObjectInputStream(byte[] bytes) throws IOException JavaDoc
45    {
46       ByteArrayInputStream JavaDoc in = new ByteArrayInputStream JavaDoc(bytes);
47       return new JBossObjectInputStreamOverride(in);
48    }
49
50    public ObjectOutputStream JavaDoc createObjectOutputStream(OutputStream JavaDoc out) throws IOException JavaDoc
51    {
52       return new JBossObjectOutputStreamSharedTree(out);
53    }
54
55 }
56
Popular Tags