/*
 * Copyright 2001-2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io.input;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import java.io.StreamCorruptedException;

/**
 * A special ObjectInputStream to handle highly transient classes hosted
 * by Avalon components that are juggling many classloaders.
 *
 * @author <a href="mailto:paul_hammant@yahoo.com">Paul Hammant</a>
 * @version $Revision$ $Date$
 */
public class ClassLoaderObjectInputStream
    extends ObjectInputStream
{
    private ClassLoader m_classLoader;

    /**
     * Constructs a new ClassLoaderObjectInputStream.
     * @param classLoader ClassLoader from which classes should be loaded.
     * @param inputStream InputStream to work on
     * @throws IOException in case of an I/O error
     * @throws StreamCorruptedException if the stream is corrupted
     */
    public ClassLoaderObjectInputStream( ClassLoader classLoader,
                                         InputStream inputStream )
        throws IOException, StreamCorruptedException
    {
        super( inputStream );
        m_classLoader = classLoader;
    }

    /** @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass) */
    protected Class resolveClass( ObjectStreamClass objectStreamClass )
        throws IOException, ClassNotFoundException
    {
        Class clazz =
            Class.forName( objectStreamClass.getName(), false, m_classLoader );

        if( null != clazz )
        {
            return clazz; // the classloader knows of the class
        }
        else
        {
            // classloader knows not of class, let the super classloader do it
            return super.resolveClass( objectStreamClass );
        }
    }
}

@@ -21,9 +21,9 @@
 -200
-4
+5
  The
@@ -861,164 +861,181 @@
 am t
-o handle highly transient classes hosted%0A * by Avalon components that are juggling many classloaders.%0A *%0A * @author %3Ca href=%22mailto:paul_hammant@yahoo.com%22%3E
+hat loads a class based on a specified%0A * %3Ccode%3EClassLoader%3C/code%3E rather than the system default.%0A * %3Cp%3E%0A * This is useful in dynamic container environments.%0A *%0A * @author 
 Paul
@@ -1046,12 +1046,8 @@
 mant
-%3C/a%3E
 %0A * 
@@ -1060,24 +1060,36 @@
 on $
-Revision$ $Date$
+Id$%0A * @since Commons IO 1.1
 %0A */
@@ -1130,20 +1130,16 @@
 utStream
-%0A   
  extends
@@ -1160,10 +1160,47 @@
 ream
-%0A%7B
+ %7B%0A%0A    /** The class loader to use. */
 %0A   
@@ -1220,18 +1220,16 @@
 sLoader 
-m_
 classLoa
@@ -1296,16 +1296,23 @@
 Stream.%0A
+     *%0A
      * @
@@ -1329,16 +1329,21 @@
 sLoader 
+ the 
 ClassLoa
@@ -1381,17 +1381,16 @@
 e loaded
-.
 %0A     * 
@@ -1408,16 +1408,21 @@
 tStream 
+ the 
 InputStr
@@ -1602,16 +1602,28 @@
 tStream(
+%0A           
  ClassLo
@@ -1643,49 +1643,8 @@
 der,
-%0A                                        
  Inp
@@ -1663,17 +1663,16 @@
 utStream
- 
 )%0A      
@@ -1665,32 +1665,36 @@
 Stream)%0A        
+    
 throws IOExcepti
@@ -1713,36 +1713,32 @@
 rruptedException
-%0A   
  %7B%0A        super
@@ -1738,17 +1738,16 @@
   super(
- 
 inputStr
@@ -1749,17 +1749,16 @@
 utStream
- 
 );%0A     
@@ -1760,18 +1760,21 @@
         
-m_
+this.
 classLoa
@@ -1812,77 +1812,18 @@
 ** @
-see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
+inheritDoc
  */%0A
@@ -1855,17 +1855,16 @@
 veClass(
- 
 ObjectSt
@@ -1890,17 +1890,16 @@
 eamClass
- 
 )%0A      
@@ -1892,32 +1892,36 @@
 mClass)%0A        
+    
 throws IOExcepti
@@ -1950,14 +1950,19 @@
 tion
+ %7B
 %0A    
-%7B
+    
 %0A   
@@ -1979,28 +1979,16 @@
  clazz =
-%0A           
  Class.f
@@ -1994,17 +1994,16 @@
 forName(
- 
 objectSt
@@ -2034,10 +2034,8 @@
 se, 
-m_
 clas
@@ -2041,17 +2041,16 @@
 ssLoader
- 
 );%0A%0A    
@@ -2059,33 +2059,24 @@
   if
-( null != clazz )%0A       
+ (clazz != null)
  %7B%0A 
@@ -2089,22 +2089,8 @@
     
- return clazz;
  // 
@@ -2136,30 +2136,40 @@
     
-%7D%0A
     
-    else%0A
+return clazz;%0A 
        
+%7D else
  %7B%0A 
@@ -2284,17 +2284,16 @@
 veClass(
- 
 objectSt
@@ -2301,17 +2301,16 @@
 eamClass
- 
 );%0A     

Format class to IO coding standards for first release