1 8 9 package com.sleepycat.bind.serial; 10 11 import java.io.IOException ; 12 import java.io.InputStream ; 13 import java.io.ObjectInputStream ; 14 import java.io.ObjectStreamClass ; 15 16 import com.sleepycat.je.DatabaseException; 17 import com.sleepycat.util.RuntimeExceptionWrapper; 18 19 34 public class SerialInput extends ObjectInputStream { 35 36 private ClassCatalog classCatalog; 37 private ClassLoader classLoader; 38 39 48 public SerialInput(InputStream in, ClassCatalog classCatalog) 49 throws IOException { 50 51 this(in, classCatalog, null); 52 } 53 54 66 public SerialInput(InputStream in, 67 ClassCatalog classCatalog, 68 ClassLoader classLoader) 69 throws IOException { 70 71 super(in); 72 73 this.classCatalog = classCatalog; 74 this.classLoader = classLoader; 75 } 76 77 protected ObjectStreamClass readClassDescriptor() 79 throws IOException , ClassNotFoundException { 80 81 try { 82 byte len = readByte(); 83 byte[] id = new byte[len]; 84 readFully(id); 85 86 return classCatalog.getClassFormat(id); 87 } catch (DatabaseException e) { 88 93 throw new RuntimeExceptionWrapper(e); 94 } 95 } 96 97 protected Class resolveClass(ObjectStreamClass desc) 99 throws IOException , ClassNotFoundException { 100 101 if (classLoader != null) { 102 try { 103 return Class.forName(desc.getName(), false, classLoader); 104 } catch (ClassNotFoundException e) { 105 return super.resolveClass(desc); 106 } 107 } else { 108 return super.resolveClass(desc); 109 } 110 } 111 } 112 | Popular Tags |