List of usage examples for java.lang Class getResourceAsStream
@CallerSensitive
public InputStream getResourceAsStream(String name)
From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java
/** * This method read Properties in the same package. <br> * If the file does not exist, throws exception. <br> * <br>// www . j av a 2 s . c om * aFileName ????? Properties ???? <br> * ?????? <br> */ public static Properties loadNecessaryPackagePrivateProperties(Class<?> aClass, String aFileName) { try { return loadProperties(aClass, aFileName, aClass.getResourceAsStream(aFileName)); } catch (NullPointerException e) { throw new RuntimeException(new FileNotFoundException(aClass.getPackage() + "." + aFileName)); } }
From source file:jp.ac.u.tokyo.m.resource.ResourceLoadUtil.java
/** * This method read Properties in the same package. <br> * If the file does not exist, logging WARN. <br> * <br>// w ww . j a v a 2s . co m * aFileName ????? Properties ???? <br> * ???????? <br> */ public static Properties loadUnnecessaryPackagePrivateProperties(Class<?> aClass, String aFileName) { try { return loadProperties(aClass, aFileName, aClass.getResourceAsStream(aFileName)); } catch (NullPointerException e) { LogFactory.getLog(aClass).warn("not found : " + aClass.getPackage() + "." + aFileName); return new Properties(); } }
From source file:org.csanchez.jenkins.plugins.kubernetes.pipeline.AbstractKubernetesPipelineTest.java
public static String loadPipelineScript(Class<?> clazz, String name) { try {//from www .j av a 2 s . co m return new String(IOUtils.toByteArray(clazz.getResourceAsStream(name))); } catch (Throwable t) { throw new RuntimeException("Could not read resource:[" + name + "]."); } }
From source file:org.javabeanstack.io.IOUtil.java
/** * Devuelve un archivo que se encuentra en la carpeta resource dentro del * proyecto donde se encuentra "clazz" la clase proporcionada como parmetro. * * @param clazz clase para ubicar el proyecto en donde se buscara el archivo * solicitado./*from www.j av a 2s . c o m*/ * @param filePath ubicacin del archivo dentro de la carpeta resource * @return un archivo en formato inputStream. */ public static InputStream getResourceAsStream(Class clazz, String filePath) { return clazz.getResourceAsStream(filePath); }
From source file:org.kuali.rice.kew.batch.KEWXmlDataLoader.java
/** * Loads the XML resource from the classloader, from the package of the specified class. * @param clazz the class whose package should be used to qualify the path * @param path the package-relative path of the XML resource * @throws Exception/* w w w . j a va2 s . c o m*/ */ public static void loadXmlPackageResource(Class clazz, String path) throws Exception { InputStream xmlFile = clazz.getResourceAsStream(path); if (xmlFile == null) { throw new WorkflowRuntimeException("Didn't find resource " + path); } try { loadXmlStream(xmlFile); } finally { xmlFile.close(); } }
From source file:com.playonlinux.qt.common.ResourceHelper.java
public static String getStyleSheet(Class<?> c, String resourcePath) { StringWriter styleWriter = new StringWriter(); InputStream styleStream = c.getResourceAsStream(resourcePath); try {//w w w . j a v a2 s .co m IOUtils.copy(styleStream, styleWriter, "UTF-8"); } catch (IOException e) { LOGGER.error(e); } return styleWriter.toString(); }
From source file:aot.util.IOUtil.java
public static Properties loadProperties(Class clazz, String name) { // log.info("Load properties '{}/{}'", clazz.getPackage().getName(), name); try (InputStream input = clazz.getResourceAsStream(name)) { Properties properties = new Properties(); properties.load(input);//from ww w. ja v a2 s .co m return properties; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:io.github.bluemarlin.util.BluemarlineUtil.java
public static String loadFromClassPath(Class<?> clazz, String classPath) { System.out.println("loadFromClassPath: " + classPath); String page = ""; try {//from w w w .ja va 2 s.c om InputStream is = clazz.getResourceAsStream(classPath); page = IOUtils.toString(is); } catch (IOException e) { System.out.println("Exception" + e.getMessage()); // won't likely happen since file is in classpath e.printStackTrace(); } return page; }
From source file:org.apache.pig.impl.util.PropertiesUtil.java
/** * Finds the file with the given file name in the classpath and loads the * properties provided in it.//from w w w.j a v a 2 s . co m * @param properties the properties object that needs to be loaded with the * property values provided in the file. * @param fileName file name of the properties' file. */ private static void loadPropertiesFromClasspath(Properties properties, String fileName) { InputStream inputStream = null; Class<PropertiesUtil> clazz = PropertiesUtil.class; try { inputStream = clazz.getResourceAsStream(fileName); if (inputStream == null) { String msg = "no " + fileName + " configuration file available in the classpath"; log.debug(msg); } else { properties.load(inputStream); } } catch (Exception e) { log.error("unable to parse " + fileName + " :", e); } finally { if (inputStream != null) try { inputStream.close(); } catch (Exception e) { } } }
From source file:org.pentaho.di.ui.util.ImageUtil.java
public static Image getImage(Display display, Class<?> resourceClass, String filename) { try {// w w w. j a v a 2 s . c o m return new Image(display, resourceClass.getResourceAsStream(filename)); } catch (Exception e) { try { return new Image(display, resourceClass.getResourceAsStream("/" + filename)); } catch (Exception e2) { return getImage(display, filename); } } }