1 /* 2 * File: CustomClassLoaderObjectInputStream.java 3 * Created: 29.05.2007 11:18:33 4 * 5 * Copyright 2007 Michal Burda. 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 package net.sf.webmancer.util.lang; 23 24 import java.io.IOException; 25 import java.io.InputStream; 26 import java.io.ObjectInputStream; 27 import java.io.ObjectStreamClass; 28 29 /** 30 * @author Michal Burda 31 * 32 */ 33 public class CustomClassLoaderObjectInputStream extends ObjectInputStream { 34 /** 35 * 36 */ 37 private ClassLoader classLoader; 38 39 /** 40 * Constructs the CustomClassLoaderObjectInputStream. 41 * 42 * @param in 43 * @param classLoader 44 * @throws IOException 45 */ 46 public CustomClassLoaderObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException { 47 super(in); 48 this.classLoader = classLoader; 49 } 50 51 /** 52 * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass) 53 */ 54 @Override 55 protected Class<?> resolveClass(ObjectStreamClass osc) throws IOException, ClassNotFoundException { 56 Class theClass = null; 57 try { 58 theClass = Class.forName(osc.getName(), true, classLoader); 59 } catch (Exception e) { 60 e.printStackTrace(); 61 } 62 return theClass; 63 } 64 }