List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:net.zcarioca.zcommons.config.source.spi.FilesystemConfigurationSourceServiceProviderTest.java
private static void copyFile(String classpathResource, File file) throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream(classpathResource); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); IOUtils.copy(in, out);/*from w w w .j av a2 s.c o m*/ IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); }
From source file:com.pinterest.pinlater.backends.redis.PinLaterRedisBackendTest.java
@BeforeClass public static void beforeClass() throws Exception { QUEUE_NAME = "pinlater_redis_backend_test"; // If there is no local Redis, skip this test. Assume.assumeTrue(LocalRedisChecker.isRunning(REDIS_PORT)); configuration = new PropertiesConfiguration(); try {/*from w w w .ja v a2s .c o m*/ configuration.load(ClassLoader.getSystemResourceAsStream("pinlater.redis.test.properties")); } catch (ConfigurationException e) { throw new RuntimeException(e); } InputStream redisConfigStream = ClassLoader.getSystemResourceAsStream("redis.local.json"); backend = new PinLaterRedisBackend(configuration, redisConfigStream, "localhost", System.currentTimeMillis()); }
From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java
@Test public void shouldThrowOnEmptyServletName() throws Exception { HierarchicalConfiguration configuration = loadConfiguration( ClassLoader.getSystemResourceAsStream("emptyservletname.xml")); assertThatThrownBy(() -> new JettyHttpServerFactory().createServers(configuration)) .isInstanceOf(ConfigurationException.class); }
From source file:hsa.awp.common.naming.TestLdapDirectoryAdapter.java
/** * Instantiates the mockery.//from w w w. ja v a 2 s . c om * * @throws IOException If the ldap configuration file was not found. */ public TestLdapDirectoryAdapter() throws IOException { mockery = new JUnit4Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; ldapConfig = new Properties(); ldapConfig.load(ClassLoader.getSystemResourceAsStream(LDAP_CONFIG_FILE)); }
From source file:org.trend.hgraph.test.AbstractHBaseMiniClusterTest.java
/** * Import local file to table./*from ww w. j a v a 2 s .c o m*/ * @param conf * @param args * @param TABLE_NAME * @param INPUT_FILE * @throws IOException * @throws InterruptedException * @throws ClassNotFoundException */ protected static void importLocalFile2Table(final Configuration conf, final String[] args, final String TABLE_NAME, final String INPUT_FILE) throws IOException, InterruptedException, ClassNotFoundException { Validate.notEmpty(INPUT_FILE, "INPUT_FILE shall not be empty or null"); InputStream ips = ClassLoader.getSystemResourceAsStream(INPUT_FILE); assertNotNull(ips); FileSystem fs = FileSystem.get(conf); FSDataOutputStream op = fs.create(new Path(INPUT_FILE), true); IOUtils.write(IOUtils.toString(ips), op, HConstants.UTF8_ENCODING); IOUtils.closeQuietly(op); IOUtils.closeQuietly(ips); int length = args.length + 2; String[] newArgs = new String[length]; System.arraycopy(args, 0, newArgs, 0, args.length); newArgs[length - 2] = TABLE_NAME; // newArgs[length - 1] = INPUT_FILE_PATH + INPUT_FILE; newArgs[length - 1] = INPUT_FILE; Job job = ImportTsv.createSubmittableJob(conf, newArgs); job.waitForCompletion(true); assertTrue(job.isSuccessful()); }
From source file:org.apache.camel.component.schematron.SchematronEndpointTest.java
@Test(expected = SchematronValidationException.class) public void testThrowSchematronValidationException() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch?abort=true"); Producer producer = endpoint.createProducer(); Exchange exchange = new DefaultExchange(context, ExchangePattern.OutIn); exchange.getIn().setBody(payload);//from ww w. j a va 2s.c o m // invoke the component. producer.process(exchange); }
From source file:com.impetus.client.cassandra.config.CassandraPropertyReader.java
@Override public void read(String pu) { Properties properties = new Properties(); try {//from ww w . j av a 2s . c o m PersistenceUnitMetadata puMetadata = KunderaMetadataManager.getPersistenceUnitMetadata(pu); String propertyName = puMetadata != null ? puMetadata.getProperty(PersistenceProperties.KUNDERA_CLIENT_PROPERTY) : null; InputStream inStream = propertyName != null ? ClassLoader.getSystemResourceAsStream(propertyName) : null; if (inStream == null) { inStream = propertyName != null ? this.getClass().getClassLoader().getResourceAsStream(propertyName) : null; } if (inStream != null) { properties.load(inStream); readKeyspaceSpecificProprerties(properties); readColumnFamilySpecificProperties(properties); } else { log.info("No property file found in class path, kundera will use default property"); } } catch (IOException e) { log.warn("error in loading properties , caused by :" + e.getMessage()); throw new KunderaException(e); } }
From source file:org.apache.airavata.datacat.agent.dispatcher.MetadataDispatcher.java
private MetadataDispatcher() throws Exception { KeyStore keyStore = KeyStore.getInstance("JKS"); KeyStore trustStore = KeyStore.getInstance("JKS"); // set up security context if (new File("../security/" + AgentProperties.getInstance().getProperty(Constants.KEYSTORE_FILE, "")) .exists()) {//from w w w . j av a 2 s .com keyStore.load( new FileInputStream(new File("../security/" + AgentProperties.getInstance().getProperty(Constants.KEYSTORE_FILE, ""))), AgentProperties.getInstance().getProperty(Constants.KEYSTORE_PWD, "").toCharArray()); } else { ; keyStore.load( ClassLoader.getSystemResourceAsStream( "security/" + AgentProperties.getInstance().getProperty(Constants.KEYSTORE_FILE, "")), AgentProperties.getInstance().getProperty(Constants.KEYSTORE_PWD, "").toCharArray()); } if (new File("../security/" + AgentProperties.getInstance().getProperty(Constants.TRUSTSTORE_FILE, "")) .exists()) { keyStore.load( new FileInputStream(new File("../security/" + AgentProperties.getInstance().getProperty(Constants.TRUSTSTORE_FILE, ""))), AgentProperties.getInstance().getProperty(Constants.TRUSTSTORE_PWD, "").toCharArray()); } else { keyStore.load( ClassLoader.getSystemResourceAsStream( "security/" + AgentProperties.getInstance().getProperty(Constants.TRUSTSTORE_FILE, "")), AgentProperties.getInstance().getProperty(Constants.TRUSTSTORE_PWD, "").toCharArray()); } SSLContext sslContext = SSLContexts.custom() .loadKeyMaterial(keyStore, AgentProperties.getInstance().getProperty(Constants.KEYSTORE_PWD, "").toCharArray()) .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build(); sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); rabbitMQPublisher = new RabbitMQPublisher(); }
From source file:ResourcesUtils.java
/** * Returns a resource on the classpath as a Stream object * /*from ww w. j av a 2s. co m*/ * @param loader * The classloader used to load the resource * @param resource * The resource to find * @throws IOException * If the resource cannot be found or read * @return The resource */ public static InputStream getResourceAsStream(ClassLoader loader, String resource) throws IOException { InputStream in = null; if (loader != null) { in = loader.getResourceAsStream(resource); } if (in == null) { in = ClassLoader.getSystemResourceAsStream(resource); } if (in == null) { throw new IOException("Could not find resource " + resource); } return in; }
From source file:org.apache.james.mailbox.tika.TikaTextExtractorTest.java
@Test public void textTest() throws Exception { InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/Text.txt"); assertThat(inputStream).isNotNull(); assertThat(textExtractor.extractContent(inputStream, "text/plain").getTextualContent()) .contains("This is some awesome text text.\n\n\n"); }