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:org.apache.tika.server.UnpackerResourceTest.java

@Test
public void testImageDOCX() throws Exception {
    Response response = WebClient.create(endPoint + UNPACKER_PATH).accept("application/zip")
            .put(ClassLoader.getSystemResourceAsStream(TEST_DOCX_IMAGE));

    Map<String, String> data = readZipArchive((InputStream) response.getEntity());
    assertEquals(DOCX_IMAGE1_MD5, data.get(DOCX_IMAGE1_NAME));
    assertEquals(DOCX_IMAGE2_MD5, data.get(DOCX_IMAGE2_NAME));
}

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

@Test
public void odsTest() throws Exception {
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("documents/calc.ods");
    assertThat(inputStream).isNotNull();
    assertThat(textExtractor.extractContent(inputStream, "application/vnd.oasis.opendocument.spreadsheet")
            .getTextualContent())//from w w  w . ja v  a  2 s  . co m
                    .contains("This is an aesome LibreOffice document!\n" + "\n" + "\n" + "???\n" + "Page \n"
                            + "??? (???)\n" + "00/00/0000, 00:00:00\n" + "Page  / \n");
}

From source file:org.apache.tika.server.TikaResourceTest.java

@Test
public void testPasswordXLSHTML() throws Exception {
    Response response = WebClient.create(endPoint + TIKA_PATH).type("application/vnd.ms-excel")
            .accept("text/html").put(ClassLoader.getSystemResourceAsStream("password.xls"));

    assertEquals(UNPROCESSEABLE, response.getStatus());
}

From source file:org.openbaton.common.vnfm_sdk.amqp.configuration.RabbitConfiguration.java

@Bean
Queue queue_genericVnfmActions() {
    Properties properties = new Properties();

    try {//  w  w  w .  j  av a  2  s  . co m
        properties.load(ClassLoader.getSystemResourceAsStream("conf.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    queueName_nfvoGenericActions = "nfvo." + properties.getProperty("type") + ".actions";
    return new Queue(queueName_nfvoGenericActions, durable, exclusive, autodelete);
}

From source file:org.obm.opush.IntegrationTestUtils.java

public InputStream streamEmail(String emailPath) {
    return ClassLoader.getSystemResourceAsStream(emailPath);
}

From source file:org.wte4j.impl.WordTemplateTest.java

private static void updateContent(WordTemplate<?> template, User user, String fileName) throws IOException {
    InputStream in = ClassLoader.getSystemResourceAsStream(fileName);
    try {// w w  w.ja  v a  2  s .c o m
        template.update(in, user);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.apache.james.mailbox.elasticsearch.json.MailboxMessageToElasticSearchJsonTest.java

@Test
public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"));
    MailboxMessage pgpSignedMail = new SimpleMailboxMessage(date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/pgpSignedMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
            propertyBuilder, MAILBOX_ID);
    pgpSignedMail.setModSeq(MOD_SEQ);//ww  w.jav  a  2s  . co  m
    pgpSignedMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/pgpSignedMail.json")));
}

From source file:org.apache.jmeter.util.JMeterUtils.java

/**
 * Load the JMeter properties file; if not found, then
 * default to "org/apache/jmeter/jmeter.properties" from the classpath
 *
 * <p>/* w  w w . jav  a  2s.co m*/
 * c.f. loadProperties
 *
 * @param file Name of the file from which the JMeter properties should be loaded
 */
public static void loadJMeterProperties(String file) {
    Properties p = new Properties(System.getProperties());
    InputStream is = null;
    try {
        File f = new File(file);
        is = new FileInputStream(f);
        p.load(is);
    } catch (IOException e) {
        try {
            is = ClassLoader.getSystemResourceAsStream("org/apache/jmeter/jmeter.properties"); // $NON-NLS-1$
            if (is == null) {
                throw new RuntimeException("Could not read JMeter properties file:" + file);
            }
            p.load(is);
        } catch (IOException ex) {
            // JMeter.fail("Could not read internal resource. " +
            // "Archive is broken.");
        }
    } finally {
        JOrphanUtils.closeQuietly(is);
    }
    appProperties = p;
}

From source file:com.semsaas.jsonxml.tools.JsonXpath.java

private static void showHelp() {
    InputStream helpStream = ClassLoader.getSystemResourceAsStream("com/semsaas/jsonxml/tools/Xpath.help");
    try {//from   w  w w  . j av a 2 s  .  c om
        IOUtils.copy(helpStream, System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.apache.tika.server.TikaResourceTest.java

@Test
public void testSimpleWordXML() throws Exception {
    Response response = WebClient.create(endPoint + TIKA_PATH).type("application/msword").accept("text/xml")
            .put(ClassLoader.getSystemResourceAsStream(TEST_DOC));
    String responseMsg = getStringFromInputStream((InputStream) response.getEntity());
    assertTrue(responseMsg.contains("test"));
}