List of usage examples for java.lang ClassLoader getResourceAsStream
public InputStream getResourceAsStream(String name)
From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java
public synchronized static X509Certificate getClass1CaCrt() throws IOException { if (class1CaCrt == null) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CLASS1_CA_CRT_FILE); class1CaCrt = PKCSReader.readCert(is); is.close();// w ww .jav a2 s .co m } return class1CaCrt; }
From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java
public synchronized static X509Certificate getClass2CaCrt() throws IOException { if (class2CaCrt == null) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CLASS2_CA_CRT_FILE); class2CaCrt = PKCSReader.readCert(is); is.close();/* ww w . ja v a2s .c om*/ } return class2CaCrt; }
From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java
public synchronized static X509Certificate getClass3CaCrt() throws IOException { if (class3RootCrt == null) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CLASS_3_CA_CRT_FILE); class3RootCrt = PKCSReader.readCert(is); is.close();/*from www . j a va2 s. co m*/ } return class3RootCrt; }
From source file:com.aqnote.shared.encrypt.cert.bc.loader.CaCertLoader.java
public synchronized static String getB64CaCrt() throws IOException { if (StringUtils.isBlank(b64CaCrt)) { ClassLoader classLoader = ClassLoaderUtil.getClassLoader(); InputStream is = classLoader.getResourceAsStream(CA_CRT_FILE); b64CaCrt = StreamUtil.stream2Bytes(is, StandardCharsets.UTF_8); b64CaCrt = StringUtils.removeStart(b64CaCrt, BEGIN_CERT); b64CaCrt = StringUtils.removeEnd(b64CaCrt, END_CERT); }/* ww w.ja va2s . c o m*/ return b64CaCrt; }
From source file:de.micromata.genome.util.runtime.Log4JInitializer.java
private static boolean initViaCp() { final ClassLoader cLoader = Log4JInitializer.class.getClassLoader(); final InputStream is = cLoader.getResourceAsStream(LOG4J_PROPERTY_FILE); if (is == null) { return false; }//w w w . j a v a 2s . co m PropertyConfigurator.configure(is); return true; }
From source file:com.centeractive.ws.common.ResourceUtils.java
public static InputStream getResourceWithAbsolutePackagePathAsStream(Class<?> clazz, String absolutePackagePath, String resourceName) {/*from w w w . j a va 2s. co m*/ checkNotNull(clazz, "clazz cannot be null"); String resourcePath = getResourcePath(absolutePackagePath, resourceName); InputStream resource = null; // first attempt - outside/inside jar file resource = clazz.getClass().getResourceAsStream(resourcePath); // second attempt - servlet container - inside application lib folder if (resource == null) { ClassLoader classLoader = clazz.getClass().getClassLoader(); if (classLoader != null) resource = classLoader.getResourceAsStream(resourcePath); } checkArgument(resource != null, String.format("Resource [%s] loading failed", resourcePath)); return resource; }
From source file:com.feilong.commons.core.configure.PropertiesUtil.java
/** * klassClassLoader,ClassLoader ?Properties. * //from w w w .j a v a 2 s. co m * @param klass * klass ClassLoader,? getResourceAsStream * @param propertiesPath * ? class {@link PropertiesUtil},? src/main/resources?, messages/feilong-core-message_en_US.properties<br> * <ul> * <li> {@link #getProperties(Class, String)} ? * {@code getProperties(PropertiesUtil.class,"/messages/feilong-core-message_en_US.properties")} <br> * ?propertiesPath ?? <b>"/messages/feilong-core-message_en_US.properties"</b>, ???</li> * <li> {@link #getPropertiesWithClassLoader(Class, String)} ? * {@code getPropertiesWithClassLoader(PropertiesUtil.class,"messages/feilong-core-message_en_US.properties")}<br> * ?propertiesPath ?? <b>"messages/feilong-core-message_en_US.properties"</b>,ClassLoader JVMBootstrapLoader?.<br> * ??"messages/feilong-core-message_en_US.properties" ??/?)</li> * </ul> * @return Properties * @see ClassLoaderUtil#getClassLoaderByClass(Class) * @see java.lang.ClassLoader#getResourceAsStream(String) * @see #getProperties(InputStream) * @see #getProperties(Class, String) */ public static Properties getPropertiesWithClassLoader(Class<?> klass, String propertiesPath) { ClassLoader classLoader = ClassLoaderUtil.getClassLoaderByClass(klass); InputStream inputStream = classLoader.getResourceAsStream(propertiesPath); return getProperties(inputStream); }
From source file:com.linkedin.drelephant.mapreduce.fetchers.MapReduceFSFetcherHadoop2Test.java
@BeforeClass public static void before() { try {//from w w w . j a v a 2 s. c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); ClassLoader classLoader = MapReduceFSFetcherHadoop2Test.class.getClassLoader(); document9 = builder .parse(classLoader.getResourceAsStream("configurations/fetcher/FetcherConfTest9.xml")); document10 = builder .parse(classLoader.getResourceAsStream("configurations/fetcher/FetcherConfTest10.xml")); document11 = builder .parse(classLoader.getResourceAsStream("configurations/fetcher/FetcherConfTest11.xml")); } catch (ParserConfigurationException e) { throw new RuntimeException("XML Parser could not be created.", e); } catch (SAXException e) { throw new RuntimeException("Test files are not properly formed", e); } catch (IOException e) { throw new RuntimeException("Unable to read test files ", e); } }
From source file:cz.hobrasoft.pdfmu.error.ErrorType.java
/** * Loads error codes from the properties resource * {@link #CODES_RESOURCE_NAME} and stores them in {@link #CODES}. *///from w ww . j a v a2 s. com private static void loadErrorCodes() { ClassLoader classLoader = ErrorType.class.getClassLoader(); InputStream in = classLoader.getResourceAsStream(CODES_RESOURCE_NAME); if (in != null) { try { CODES.load(in); } catch (IOException ex) { LOGGER.severe(String.format("Could not load the error codes properties file: %s", ex)); } try { in.close(); } catch (IOException ex) { LOGGER.severe(String.format("Could not close the error codes properties file: %s", ex)); } } else { LOGGER.severe("Could not open the error codes properties file."); } }
From source file:cn.ctyun.amazonaws.regions.RegionUtils.java
/** * Failsafe method to initialize the regions list from the list bundled with * the SDK, in case it cannot be fetched from the remote source. *//*www . j a v a 2 s. c o m*/ private static void initSDKRegions() { ClassLoader classLoader = RegionUtils.class.getClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("/etc/regions.xml"); initRegions(inputStream); }