Example usage for java.lang ClassLoader getSystemResourceAsStream

List of usage examples for java.lang ClassLoader getSystemResourceAsStream

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResourceAsStream.

Prototype

public static InputStream getSystemResourceAsStream(String name) 

Source Link

Document

Open for reading, a resource of the specified name from the search path used to load classes.

Usage

From source file:com.semsaas.jsonxml.tests.Tests.java

public void xjson2json(String xmlResource, String jsonResource) {
    InputStream is = ClassLoader.getSystemResourceAsStream(xmlResource);
    try {/*from   w ww.  j  a  va2  s  .c  o m*/
        // The real test
        StringWriter result = new StringWriter();
        Examples.XJson2json.xjson2json(is, result);

        // Check the results         
        StringWriter expected = new StringWriter();
        InputStream xmlIs = ClassLoader.getSystemResourceAsStream(jsonResource);
        IOUtils.copy(xmlIs, expected);

        assertEquals(expected.toString().replaceAll("[\\n\\s]+", ""),
                result.toString().replaceAll("[\\n\\s]+", ""));

    } catch (SAXException e) {
        fail(e.getMessage());
    } catch (IOException e) {
        fail(e.getMessage());
    }
}

From source file:com.pinterest.pinlater.backends.mysql.MySQLQueueMonitorTest.java

@Before
public void beforeTest() throws Exception {
    // If there is no local MySQL, skip this test.
    boolean isLocalMysqlRunning = LocalMySQLChecker.isRunning();
    Assume.assumeTrue(isLocalMysqlRunning);

    configuration = new PropertiesConfiguration();
    try {//from w w w  . j  ava  2  s. c o m
        configuration.load(ClassLoader.getSystemResourceAsStream("pinlater.test.properties"));
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    System.setProperty("backend_config", "mysql.local.json");

    backend = new PinLaterMySQLBackend(configuration, "localhost", System.currentTimeMillis());

    // Delete the test queue, if it exists already, for some reason.
    backend.deleteQueue(QUEUE_NAME).get();

    // Now create it.
    backend.createQueue(QUEUE_NAME).get();
}

From source file:de.uzk.hki.da.sb.SIPFactoryTests.java

@Before
public void setUp() {

    Logger logger = Logger.getRootLogger();
    logger.setLevel(Level.ERROR);

    new File(pathToResourcesFolder + "destination").mkdir();

    ProgressManager progressManager = mock(ProgressManager.class);
    MessageWriter messageWriter = mock(MessageWriter.class);
    de.uzk.hki.da.sb.Logger sipLogger = mock(de.uzk.hki.da.sb.Logger.class);

    sipFactory = new SIPFactory();
    sipFactory.setProgressManager(progressManager);
    sipFactory.setMessageWriter(messageWriter);
    sipFactory.setLogger(sipLogger);//from w  w  w .ja  v  a2  s.c  om

    Properties properties = new Properties();
    try {
        properties.load(new InputStreamReader(
                (ClassLoader.getSystemResourceAsStream("configuration/config.properties"))));
    } catch (FileNotFoundException e1) {
        System.exit(SIPFactory.Feedback.GUI_ERROR.toInt());
    } catch (IOException e2) {
        System.exit(SIPFactory.Feedback.GUI_ERROR.toInt());
    }
    SIPBuilder.setProperties(properties);
}

From source file:org.apache.james.mailbox.tika.ContentTypeFilteringTextExtractorTest.java

@Test
public void extractContentCallUnderlyingWithContentTypeNotInBlacklist() throws Exception {
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/Text.txt");
    ContentTypeFilteringTextExtractor contentTypeFilteringTextExtractor = new ContentTypeFilteringTextExtractor(
            textExtractor, ImmutableSet.of("application/ics", "application/zip"));
    contentTypeFilteringTextExtractor.extractContent(inputStream, "text/plain");

    verify(textExtractor, times(1)).extractContent(any(), any());
}

From source file:com.github.jcooky.jaal.agent.bytecode.asm.ASM5ProfilingTest.java

@Test
public void testInject() throws Throwable {
    InjectorStrategy is = new ProfilingInjectorStrategy(ProfilerFactory.class.getName(), Restrictions.any());
    ASM5Injector injector = new ASM5Injector(is);

    Class<?> cls = classLoader.defineClass(injector.inject(IOUtils.toByteArray(
            ClassLoader.getSystemResourceAsStream(Target.class.getName().replace('.', '/') + ".class"))));

    Object self = cls.newInstance();
    String str = (String) cls.getMethod("methodTarget").invoke(self);
    assertThat(str, is("hello world123"));
    str = (String) cls.getMethod("method", boolean.class).invoke(null, false);
    assertThat(str, is("Test"));

    verify(ProfilerFactory.PROFILER, times(3)).begin(any(ClassType.class), any(MethodType.class));
    verify(ProfilerFactory.PROFILER, times(3)).end(any(ClassType.class), any(MethodType.class), anyLong(),
            any(Throwable.class), anyLong());
}

From source file:org.sejda.core.context.XmlConfigurationStreamProvider.java

private InputStream getCustomConfigurationStream(String userConfigFileName) throws ConfigurationException {
    LOG.debug("Loading Sejda configuration form {}", userConfigFileName);
    InputStream retVal = ClassLoader.getSystemResourceAsStream(userConfigFileName);
    if (retVal == null) {
        try {//from  w  w w  .  j a v  a  2s . c  om
            LOG.debug("Searching Sejda configuration on filesystem");
            return new FileInputStream(userConfigFileName);
        } catch (FileNotFoundException e) {
            throw new ConfigurationException(
                    String.format("Unable to access the provided configuration file [%s]", userConfigFileName),
                    e);
        }
    }
    return retVal;
}

From source file:Resources.java

/**
 * Returns a resource on the classpath as a Stream object
 *
 * @param loader   The classloader used to load the resource
 * @param resource The resource to find/*from  www . jav  a  2 s . c o  m*/
 * @return The resource
 * @throws IOException If the resource cannot be found or read
 */
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:com.codenvy.dev.shell.view.ShellBannerProvider.java

@Override
public String getVersion() {
    try (InputStream is = ClassLoader.getSystemResourceAsStream("BuildNumber.properties")) {
        Properties buildInfo = new Properties();
        buildInfo.load(is);/*from  www .  ja va  2  s  .co m*/

        return String.format("v%s, %s, rev. %s", buildInfo.getProperty("version"),
                buildInfo.getProperty("buildTime"), buildInfo.getProperty("buildNumber"));
    } catch (IOException e) {
        return "undefined";
    }
}

From source file:org.langera.freud.optional.css.cssrule.CssRuleJdomTest.java

@Before
public void setUp() throws Exception {
    final SAXBuilder saxBuilder = new SAXBuilder(false);
    Document document = saxBuilder.build(ClassLoader.getSystemResourceAsStream("parsed_css_example.xml"));
    JXPathContext context = JXPathContext.newContext(document.getRootElement());
    cssRuleJdom = new CssRuleJdom((Element) context.selectSingleNode("//RULE[3]"), 0);
    cssRuleJdomSeparatedByCommas0 = new CssRuleJdom((Element) context.selectSingleNode("//RULE[2]"), 0);
    cssRuleJdomSeparatedByCommas1 = new CssRuleJdom((Element) context.selectSingleNode("//RULE[2]"), 1);
}

From source file:org.apache.camel.component.schematron.processor.SchematronProcessorTest.java

/**
 * Returns schematron processor/*from ww w.  ja va2s .c om*/
 *
 * @param schematron
 * @return
 */
private SchematronProcessor getProcessor(final String schematron) {
    Templates rules = TemplatesFactory.newInstance()
            .newTemplates(ClassLoader.getSystemResourceAsStream(schematron));
    return SchematronProcessorFactory.newScehamtronEngine(rules);
}