All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.util.ObjectInputStreamWithClassloader Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 32.0.0.Final
Show newest version
package org.jgroups.util;

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

/**
 * Override {@link java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)} using the passed-in
 * classloader
 * @author Bela Ban
 * @since  3.5
 */
public class ObjectInputStreamWithClassloader extends ObjectInputStream {
    protected final ClassLoader loader;

    public ObjectInputStreamWithClassloader(InputStream in) throws IOException {
        this(in, null);
    }

    public ObjectInputStreamWithClassloader(InputStream in, ClassLoader loader) throws IOException {
        super(in);
        this.loader=loader;
    }

    protected ObjectInputStreamWithClassloader() throws IOException, SecurityException {
        this((ClassLoader)null);
    }

    protected ObjectInputStreamWithClassloader(ClassLoader loader) throws IOException, SecurityException {
        this.loader=loader;
    }

    @Override
    protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        if(loader == null)
            return super.resolveClass(desc);

        String name=desc.getName();
        try {
            return Class.forName(name, false, loader);
        }
        catch (ClassNotFoundException ex) {
            Class cl=super.resolveClass(desc);
            if(cl != null)
                return cl;
            throw ex;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy