List of usage examples for java.lang ClassLoader getSystemResourceAsStream
public static InputStream getSystemResourceAsStream(String name)
From source file:org.apromore.canoniser.epml.AbstractTest.java
/** * @param resource the name of a resource within the <code>EPML/</code> directory of the classpath, minus its <code>.epml</code> extension *//*from ww w. ja v a2 s . co m*/ public void testCanonise(final String resource) throws CanoniserException, PropertyException, JAXBException, SAXException, FileNotFoundException, IOException { EPML20Canoniser c = new EPML20Canoniser(); ArrayList<AnnotationsType> anfList = new ArrayList<>(); ArrayList<CanonicalProcessType> cpfList = new ArrayList<>(); c.canonise(ClassLoader.getSystemResourceAsStream("EPML/" + resource + ".epml"), anfList, cpfList, new PluginRequestImpl()); assertFalse(anfList.isEmpty()); assertFalse(cpfList.isEmpty()); try (FileOutputStream cpfOut = new FileOutputStream("target/" + resource + ".epml.cpf"); FileOutputStream anfOut = new FileOutputStream("target/" + resource + ".epml.anf")) { // Unvalidated write to the target directory CPFSchema.marshalCanonicalFormat(cpfOut, cpfList.get(0), false); ANFSchema.marshalAnnotationFormat(anfOut, anfList.get(0), false); // Validation pass CPFSchema.marshalCanonicalFormat(new NullOutputStream(), cpfList.get(0), true); ANFSchema.marshalAnnotationFormat(new NullOutputStream(), anfList.get(0), true); } }
From source file:org.vanbest.xmltv.Config.java
private Config() { Properties configProp = new Properties(); InputStream in = ClassLoader.getSystemResourceAsStream("tv_grab_nl_java.properties"); try {/*from ww w . j a v a 2 s . c o m*/ configProp.load(in); } catch (IOException e) { logger.warn("Error reading application properties from tv_grab_nl_java.properties resource"); logger.debug("stack trace: ", e); } project_version = configProp.getProperty("project.version"); build_time = configProp.getProperty("build.time"); }
From source file:TikaServiceWinRun4J.java
public int serviceMain(String[] args) { Properties properties = new Properties(); try {// www . j a v a2 s.c o m properties.load(ClassLoader.getSystemResourceAsStream("tikaserver-version.properties")); } catch (IOException e) { throw new RuntimeException(e); } logger.info("Starting Tika server " + properties.getProperty("tikaserver.version")); try { Options options = getOptions(); CommandLineParser cliParser = new GnuParser(); CommandLine line = cliParser.parse(options, args); int port = DEFAULT_PORT; if (line.hasOption("port")) { port = Integer.valueOf(line.getOptionValue("port")); } if (line.hasOption("help")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("tikaserver", options); System.exit(-1); } server = new Server(port); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet( new ServletHolder(new ServletContainer(new PackagesResourceConfig("org.apache.tika.server"))), "/*"); server.start(); logger.info("Started"); server.join(); return 0; } catch (Exception ex) { logger.fatal("Can't start", ex); return 1; } }
From source file:com.glweb.util.GlobalProperties.java
private GlobalProperties() { _logger = LogFactory.getLog("com.glweb.util.GlobalProperties"); try {/*from w w w. ja v a 2 s. co m*/ InputStream _in = ClassLoader.getSystemResourceAsStream(CONFIG); if (null == _in) { _logger.warn("<Unable to find the global properties from system resources/>"); _logger.warn("<Try to find the global properties from class resources/>"); _in = getClass().getResourceAsStream(CONFIG); if (null == _in) { _logger.warn("<Unable to find the global properties from class resources/>"); } else { _logger.info("<Found the global properties from class resources/>"); } } else { _logger.info("<Found the global properties from system resources/>"); } getGlobalProperties().load(_in); } catch (IOException ioe) { _logger.error("<Unable to read global properties!/>"); } }
From source file:net.gazeplay.commons.utils.games.Utils.java
public static InputStream getInputStream(String ressource) { log.debug("Try to play " + ressource); return ClassLoader.getSystemResourceAsStream(ressource); }
From source file:org.apache.camel.component.schematron.SchematronEndpointTest.java
@Test public void testSchematronFileReadFromFileSystem() throws Exception { String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-2.xml")); String path = ClassLoader.getSystemResource("sch/schematron-1.sch").getPath(); Endpoint endpoint = context().getEndpoint("schematron://" + path); Producer producer = endpoint.createProducer(); Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut); exchange.getIn().setBody(payload);// w ww.j a v a 2 s. c o m // invoke the component. producer.process(exchange); String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class); assertNotNull(report); }
From source file:ResourcesUtils.java
/** * Returns a resource on the classpath as a Stream object * //www . j a v a 2 s .c o m * @param resource * The resource to find * @throws IOException * If the resource cannot be found or read * @return The resource */ public static InputStream getResourceAsStream(String resource) throws IOException { InputStream in = null; ClassLoader loader = ResourcesUtils.class.getClassLoader(); 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:com.sonatype.security.ldap.AbstractMockLdapConnectorTest.java
public void setUp() throws Exception { super.setUp(); String filename = "ldap.xml"; String resourcePath = this.getClass().getName().replace('.', '/'); resourcePath += "-" + filename; if (ClassLoader.getSystemResource(resourcePath) == null) { resourcePath = "defaults/" + filename; }/*from w ww . j a va2 s . co m*/ getConfHomeDir().mkdirs(); Map<String, String> interpolationMap = new HashMap<String, String>(); interpolationMap.put("default-ldap-port", "12345"); try (InterpolationFilterReader reader = new InterpolationFilterReader( new InputStreamReader(ClassLoader.getSystemResourceAsStream(resourcePath)), interpolationMap); OutputStream out = new FileOutputStream(new File(getConfHomeDir(), "ldap.xml"));) { IOUtils.copy(reader, out); } this.ldapManager = (EnterpriseLdapManager) this.lookup(LdapManager.class); this.resetLdapConnectors(); }
From source file:org.apache.james.http.jetty.JettyHttpServerFactoryTest.java
@Test public void shouldCreateServersAsDescribedInXmlConfiguration() throws Exception { HierarchicalConfiguration configuration = loadConfiguration( ClassLoader.getSystemResourceAsStream("httpserver.xml")); List<JettyHttpServer> servers = new JettyHttpServerFactory().createServers(configuration); assertThat(servers).extracting(JettyHttpServer::getConfiguration).containsOnly( Configuration.builder().port(5000).serve("/foo").with(Ok200.class).serve("/bar").with(Bad400.class) .build(),/*from w w w.jav a 2 s.co m*/ Configuration.builder().randomPort().serve("/foo").with(Ok200.class).filter("/*") .with(SpyFilter.class).only().build()); }
From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java
/** * @throws IOException/*w w w .j a va2 s . c o m*/ * @throws PrivateEc2ParserException * */ @Test public void testTemplateWithEBS() throws IOException, PrivateEc2ParserException { InputStream templateStream = ClassLoader .getSystemResourceAsStream("./cfn_templates/EC2WithEBSSample.template"); PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream); assertNotNull(template); assertNotNull(template.getEC2Instance()); assertNotNull(template.getEC2Instance().getProperties()); assertNotNull(template.getEC2Instance().getProperties().getVolumes()); assertEquals(1, template.getEC2Instance().getProperties().getVolumes().size()); assertNotNull(template.getEC2Instance().getProperties().getVolumes().get(0).getVolumeId()); assertNotNull("NewVolume", template.getEC2Instance().getProperties().getVolumes().get(0).getVolumeId().getValue()); assertNotNull(template.getEC2Volume("NewVolume")); }