KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > util > MagicObjectInputStream


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 JavaDoc;
9 import java.io.InputStream JavaDoc;
10 import java.io.ObjectStreamClass JavaDoc;
11
12 /**
13  * Uses magic numbers for class descriptors
14  * @author Bela Ban
15  * @version $Id: MagicObjectInputStream.java,v 1.4 2004/10/04 20:47:57 belaban Exp $
16  */

17 public class MagicObjectInputStream extends ContextObjectInputStream {
18     static ClassConfigurator conf=null;
19     static final Log log=LogFactory.getLog(MagicObjectInputStream.class);
20
21
22     public MagicObjectInputStream(InputStream JavaDoc is) throws IOException JavaDoc {
23         super(is);
24         if(conf == null) {
25             try {
26                 conf=ClassConfigurator.getInstance(false);
27             }
28             catch(ChannelException e) {
29                 log.error("ClassConfigurator could not be instantiated", e);
30             }
31         }
32     }
33
34
35     protected ObjectStreamClass JavaDoc readClassDescriptor() throws IOException JavaDoc, ClassNotFoundException JavaDoc {
36         ObjectStreamClass JavaDoc retval;
37         int magic_num=super.readInt();
38
39         if(conf == null || magic_num == -1) {
40             return super.readClassDescriptor();
41         }
42
43         retval=conf.getObjectStreamClassFromMagicNumber(magic_num);
44         if(retval == null)
45             throw new ClassNotFoundException JavaDoc("failed fetching class descriptor for magic number " + magic_num);
46         //if(log.isTraceEnabled())
47
//log.trace("reading descriptor (from " + magic_num + "): " + retval.getName());
48
return retval;
49     }
50 }
51
52
Popular Tags