01: package org.jgroups.util;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05: import org.jgroups.ChannelException;
06: import org.jgroups.conf.ClassConfigurator;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10: import java.io.ObjectStreamClass;
11:
12: /**
13: * Uses magic numbers for class descriptors
14: * @author Bela Ban
15: * @version $Id: MagicObjectInputStream.java,v 1.5 2006/02/27 14:13:30 belaban Exp $
16: */
17: public class MagicObjectInputStream extends ContextObjectInputStream {
18: static volatile ClassConfigurator conf = null;
19: static final Log log = LogFactory
20: .getLog(MagicObjectInputStream.class);
21:
22: public MagicObjectInputStream(InputStream is) throws IOException {
23: super (is);
24: if (conf == null) {
25: try {
26: conf = ClassConfigurator.getInstance(false);
27: } catch (ChannelException e) {
28: log.error(
29: "ClassConfigurator could not be instantiated",
30: e);
31: }
32: }
33: }
34:
35: protected ObjectStreamClass readClassDescriptor()
36: throws IOException, ClassNotFoundException {
37: ObjectStreamClass retval;
38: int magic_num = super .readInt();
39:
40: if (conf == null || magic_num == -1) {
41: return super .readClassDescriptor();
42: }
43:
44: retval = conf.getObjectStreamClassFromMagicNumber(magic_num);
45: if (retval == null)
46: throw new ClassNotFoundException(
47: "failed fetching class descriptor for magic number "
48: + magic_num);
49: //if(log.isTraceEnabled())
50: //log.trace("reading descriptor (from " + magic_num + "): " + retval.getName());
51: return retval;
52: }
53: }
|