Here you can find the source of getClassInputStream(String className, ClassLoader cl)
public static InputStream getClassInputStream(String className, ClassLoader cl)
//package com.java2s; /*// www.ja v a 2 s.c o m * Copyright (c) 2015, Parallel Universe Software Co. All rights reserved. * * This program and the accompanying materials are licensed under * GNU General Public License, version 2, with the Classpath Exception * * http://openjdk.java.net/legal/gplv2+ce.html */ import java.io.InputStream; public class Main { private static final String CLASS_FILE_NAME_EXTENSION = ".class"; public static InputStream getClassInputStream(String className, ClassLoader cl) { return cl.getResourceAsStream(classToResource(className)); } public static InputStream getClassInputStream(Class<?> clazz) { final InputStream is = getClassInputStream(clazz.getName(), clazz.getClassLoader()); if (is == null) throw new UnsupportedOperationException("Class file " + clazz.getName() + " could not be loaded by the class's classloader " + clazz.getClassLoader()); return is; } public static String classToResource(String className) { if (className == null) return null; return className.replace('.', '/') + CLASS_FILE_NAME_EXTENSION; } public static String classToResource(Class<?> clazz) { if (clazz == null) return null; return classToResource(clazz.getName()); } }