Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

SerialInput.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: SerialInput.java,v 12.2 2005/08/01 20:25:06 mark Exp $
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     // javadoc is specified elsewhere
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              * Do not throw IOException from here since ObjectOutputStream
00091              * will write the exception to the stream, which causes another
00092              * call here, etc.
00093              */
00094             throw new RuntimeExceptionWrapper(e);
00095         }
00096     }
00097 
00098     // javadoc is specified elsewhere
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 }

Generated on Sun Dec 25 12:14:30 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2