00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.bind.serial;
00011
00012 import java.io.IOException;
00013 import java.io.InputStream;
00014 import java.io.ObjectInputStream;
00015 import java.io.ObjectStreamClass;
00016
00017 import com.sleepycat.db.DatabaseException;
00018 import com.sleepycat.util.RuntimeExceptionWrapper;
00019
00035 public class SerialInput extends ObjectInputStream {
00036
00037 private ClassCatalog classCatalog;
00038 private ClassLoader classLoader;
00039
00049 public SerialInput(InputStream in, ClassCatalog classCatalog)
00050 throws IOException {
00051
00052 this(in, classCatalog, null);
00053 }
00054
00067 public SerialInput(InputStream in,
00068 ClassCatalog classCatalog,
00069 ClassLoader classLoader)
00070 throws IOException {
00071
00072 super(in);
00073
00074 this.classCatalog = classCatalog;
00075 this.classLoader = classLoader;
00076 }
00077
00078
00079 protected ObjectStreamClass readClassDescriptor()
00080 throws IOException, ClassNotFoundException {
00081
00082 try {
00083 byte len = readByte();
00084 byte[] id = new byte[len];
00085 readFully(id);
00086
00087 return classCatalog.getClassFormat(id);
00088 } catch (DatabaseException e) {
00089
00090
00091
00092
00093
00094 throw new RuntimeExceptionWrapper(e);
00095 }
00096 }
00097
00098
00099 protected Class resolveClass(ObjectStreamClass desc)
00100 throws IOException, ClassNotFoundException {
00101
00102 if (classLoader != null) {
00103 try {
00104 return Class.forName(desc.getName(), false, classLoader);
00105 } catch (ClassNotFoundException e) {
00106 return super.resolveClass(desc);
00107 }
00108 } else {
00109 return super.resolveClass(desc);
00110 }
00111 }
00112 }