Here you can find the source of getResourceAsStream(String name, Class aClass)
Parameter | Description |
---|---|
name | the name of the resource to return |
aClass | the class which class loader to use |
public static InputStream getResourceAsStream(String name, Class aClass)
//package com.java2s; //License from project: Apache License import java.io.InputStream; public class Main { /**/*from w w w . j av a2 s. com*/ * Return the input stream for the given name and class. * * @param name the name of the resource to return * @param aClass the class which class loader to use * @return the input stream for the given name and class */ public static InputStream getResourceAsStream(String name, Class aClass) { if (isBlank(name)) { throw new IllegalArgumentException("Parameter name cannot be blank"); } ; if (aClass == null) { throw new IllegalArgumentException("Parameter aClass is null"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream(name); if (inputStream == null) { inputStream = aClass.getResourceAsStream(name); } return inputStream; } /** * Checks if a String is whitespace, empty ("") or null. * <p/> * * @param str the String to check, may be null * @return <code>true</code> if the String is null, empty or whitespace */ public static boolean isBlank(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return true; } for (int i = 0; i < strLen; i++) { if ((Character.isWhitespace(str.charAt(i)) == false)) { return false; } } return true; } }