List of usage examples for java.lang ClassLoader getResourceAsStream
public InputStream getResourceAsStream(String name)
From source file:com.ericsson.eiffel.remrem.semantics.validator.EiffelValidator.java
public EiffelValidator(String schemaResourceName, String eventType, List<String> requiredLinkTypes, List<String> optionalLinkTypes, List<String> allLinkTypes) { this.schemaResourceName = schemaResourceName; this.eventType = eventType; this.requiredLinkTypes = requiredLinkTypes; this.optionalLinkTypes = optionalLinkTypes; this.allLinkTypes = allLinkTypes; ObjectMapper mapper = new ObjectMapper(); JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); ClassLoader classLoader = getClass().getClassLoader(); try {/*from w w w .j ava2s .co m*/ validationSchema = factory .getJsonSchema(mapper.readTree(classLoader.getResourceAsStream(schemaResourceName))); log.debug("Validation schema loaded: {}", schemaResourceName); } catch (Exception e) { String message = "Cannot parse JSON schema. The resource: " + schemaResourceName + ". " + e.getClass() + ": " + e.getMessage(); log.error(message, e); throw new IllegalArgumentException(message, e); } }
From source file:com.sample.partnerprofile.util.ConnectionPool.java
private ConnectionPool() { try {//from w w w. j a va 2s.c o m // Properties ClassLoader classLoader = getClass().getClassLoader(); _props = new Properties(); _props.load(classLoader.getResourceAsStream("connection-pool.properties")); _props.list(System.out); // Pooled data source String driverClass = _props.getProperty("driver.class"); String jdbcUrl = _props.getProperty("jdbc.url"); String user = _props.getProperty("user"); String password = _props.getProperty("password"); int minPoolSize = 5; try { minPoolSize = Integer.parseInt(_props.getProperty("min.pool.size")); } catch (Exception e) { } int maxPoolSize = 5; try { maxPoolSize = Integer.parseInt(_props.getProperty("max.pool.size")); } catch (Exception e) { } int acquireIncrement = 5; try { acquireIncrement = Integer.parseInt(_props.getProperty("acquire.increment")); } catch (Exception e) { } _cpds = new ComboPooledDataSource(); _cpds.setDriverClass(driverClass); _cpds.setJdbcUrl(jdbcUrl); _cpds.setUser(user); _cpds.setPassword(password); _cpds.setMinPoolSize(minPoolSize); _cpds.setMaxPoolSize(maxPoolSize); _cpds.setAcquireIncrement(acquireIncrement); } catch (Exception e) { _log.error(e); } }
From source file:com.liferay.geoipusersmap.util.LPortalConnectionPool.java
private LPortalConnectionPool() { try {//from w w w . j av a 2s . co m // Properties ClassLoader classLoader = getClass().getClassLoader(); _props = new Properties(); _props.load(classLoader.getResourceAsStream("lportal-connection-pool.properties")); //_props.list(System.out); // Pooled data source String driverClass = _props.getProperty("driver.class"); String jdbcUrl = _props.getProperty("jdbc.url"); String user = _props.getProperty("user"); String password = _props.getProperty("password"); int minPoolSize = 5; try { minPoolSize = Integer.parseInt(_props.getProperty("min.pool.size")); } catch (Exception e) { } int maxPoolSize = 5; try { maxPoolSize = Integer.parseInt(_props.getProperty("max.pool.size")); } catch (Exception e) { } int acquireIncrement = 5; try { acquireIncrement = Integer.parseInt(_props.getProperty("acquire.increment")); } catch (Exception e) { } _cpds = new ComboPooledDataSource(); _cpds.setDriverClass(driverClass); _cpds.setJdbcUrl(jdbcUrl); _cpds.setUser(user); _cpds.setPassword(password); _cpds.setMinPoolSize(minPoolSize); _cpds.setMaxPoolSize(maxPoolSize); _cpds.setAcquireIncrement(acquireIncrement); } catch (Exception e) { _log.error(e); } }
From source file:egpi.tes.ahv.servicio.AutenticacionREST.java
/** * //from ww w . j a v a2s. c o m * @throws IOException */ public void cargarPropiedades() throws IOException, ReporteJasperException { try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("/servidorreportes.properties"); properties = new Properties(); if (inputStream != null) { properties.load(inputStream); } else { throw new ReporteJasperException( "Verifique que exista fichero /classes/servidorreportes.properties "); } } catch (Exception e) { e.printStackTrace(); throw new ReporteJasperException(e.getMessage()); } }
From source file:Engine.Lua.PlayerLua.java
public PlayerLua(String luaFile) { ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngine scriptEngine = sem.getEngineByName("luaj"); ClassLoader classloader = Thread.currentThread().getContextClassLoader(); InputStream is = classloader.getResourceAsStream("Scripts/" + luaFile); InputStreamReader isr = new InputStreamReader(is); CompiledScript script;//w w w.ja v a 2 s . com try { script = ((Compilable) scriptEngine).compile(isr); isr.close(); is.close(); sb = new SimpleBindings(); script.eval(sb); // Put the Lua functions into the sb environment } catch (ScriptException ex) { Logger.getLogger(PlayerLua.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(PlayerLua.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.liferay.portal.spring.hibernate.PortalHibernateConfiguration.java
protected void readResource(Configuration configuration, String resource) throws Exception { ClassLoader classLoader = getConfigurationClassLoader(); if (!resource.startsWith("classpath*:")) { InputStream is = classLoader.getResourceAsStream(resource); readResource(configuration, resource, is); } else {/* w w w . ja v a2s . c om*/ String resourceName = resource.substring("classpath*:".length()); try { Enumeration<URL> resources = classLoader.getResources(resourceName); if (_log.isDebugEnabled() && !resources.hasMoreElements()) { _log.debug("No " + resourceName + " has been found"); } while (resources.hasMoreElements()) { URL resourceFullName = resources.nextElement(); try { InputStream is = new UrlResource(resourceFullName).getInputStream(); readResource(configuration, resource, is); } catch (Exception e2) { if (_log.isWarnEnabled()) { _log.warn("Problem while loading " + resource, e2); } } } } catch (Exception e2) { if (_log.isWarnEnabled()) { _log.warn("Problem while loading classLoader resources: " + resourceName, e2); } } } }
From source file:org.alfresco.repo.workflow.activiti.ActivitiSpringTest.java
/** * {@inheritDoc}/*from ww w . j a va 2 s . co m*/ */ @Override protected void setUp() throws Exception { ConfigurableApplicationContext appContext = loadContext(); this.repo = (RepositoryService) appContext.getBean("activitiRepositoryService"); this.runtime = (RuntimeService) appContext.getBean("activitiRuntimeService"); ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY); authenticationComponent = (AuthenticationComponent) appContext.getBean("authenticationComponent"); TransactionService transactionService = serviceRegistry.getTransactionService(); nodeService = serviceRegistry.getNodeService(); txnHelper = transactionService.getRetryingTransactionHelper(); // authenticate authenticationComponent.setSystemUserAsCurrentUser(); StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "test-" + getName() + "-" + System.currentTimeMillis()); NodeRef rootNodeRef = nodeService.getRootNode(storeRef); // Create a node to work on workingNodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, getName()), ContentModel.TYPE_CMOBJECT) .getChildRef(); String resource = "org/alfresco/repo/workflow/activiti/testTransaction.bpmn20.xml"; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); InputStream input = classLoader.getResourceAsStream(resource); this.deployment = repo.createDeployment().addInputStream(resource, input).deploy(); }
From source file:com.messagehub.samples.MessageHubJavaSample.java
/** * Retrieve client configuration information, using a properties file, for * connecting to secure Kafka.//w ww .java 2 s .co m * * @param broker * {String} A string representing a list of brokers the producer * can contact. * @param apiKey * {String} The API key of the Bluemix Message Hub service. * @param isProducer * {Boolean} Flag used to determine whether or not the * configuration is for a producer. * @return {Properties} A properties object which stores the client * configuration info. */ public final Properties getClientConfiguration(String broker, String apiKey, boolean isProducer) { Properties props = new Properties(); InputStream propsStream; String fileName = "resources/producer.properties"; try { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); propsStream = classLoader.getResourceAsStream(fileName); props.load(propsStream); propsStream.close(); } catch (IOException e) { logger.log(Level.ERROR, "Could not load properties from file"); return props; } System.out.println("+++++++++++++++++++++++++++bootstrap.servers:: " + broker); props.put("bootstrap.servers", broker); return props; }
From source file:com.edgenius.wiki.render.impl.MacroManagerImpl.java
public void load() { ClassLoader classLoader = Macro.class.getClassLoader(); BufferedReader is = null;// ww w . j a v a 2 s .c o m try { is = new BufferedReader(new InputStreamReader(classLoader.getResourceAsStream(macroResource))); String macroClz; while ((macroClz = is.readLine()) != null) { //get macro class if (StringUtils.isBlank(macroClz) || macroClz.trim().startsWith("#")) { //skip comment continue; } try { Object obj = classLoader.loadClass(macroClz.trim()).newInstance(); if (obj instanceof Macro) { Macro macro = (Macro) obj; macro.init(applicationContext); String[] names = macro.getName(); container.put(names, macro); log.info("Macro class loading success:" + names[0]); //put to containerIndex, so that macro can quick locate when try to get by name for (String name : names) { containerIndex.put(name.toLowerCase(), names); } if (obj instanceof ImmutableContentMacro) { if (!macro.isPaired()) { AuditLogger.error( "Unexpected case: ImmutableMacro is not paired macro, is that correct?" + Arrays.toString(macro.getName())); throw new Exception( "Unexpected case: ImmutableMacro is not paired macro, is that correct?" + Arrays.toString(macro.getName())); } immutableContentMacroMap.add(macro); } } } catch (Exception e) { log.error("Initial macro class " + macroClz + " failed. This macro is ignored!!!", e); } } } catch (IOException e) { log.error("Macro resource file " + macroResource + " not found.", e); } finally { IOUtils.closeQuietly(is); } }
From source file:at.ac.tuwien.infosys.jcloudscale.test.unit.ClassLoaderTest.java
@Test(timeout = TIMEOUT) public void testSystemClassLoader() throws Exception { SystemClassLoaderConfiguration classLoaderConfiguration = new SystemClassLoaderConfiguration(); startup(classLoaderConfiguration);/* w ww . jav a2s.c om*/ ClassLoader classLoader = classLoaderConfiguration.createClassLoader(); assertSame(ClassLoader.getSystemClassLoader().getClass(), classLoader.getClass()); InputStream stream = classLoader.getResourceAsStream(RESOURCE); assertNotNull(stream); assertEquals(CONTENT, IOUtils.toString(stream)); }