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.pinterest.pinlater.PinLaterServer.java

private static PinLaterBackendIface getBackendIface(String backend, String serverHostName) throws Exception {
    InputStream backendConfigStream = ClassLoader
            .getSystemResourceAsStream(System.getProperty("backend_config"));
    if (backend != null && backend.equals("redis")) {
        return new PinLaterRedisBackend(CONFIGURATION, backendConfigStream, serverHostName,
                SERVER_START_TIME_MILLIS);
    } else {// w  w w . j  av a 2  s  .  c  om
        return new PinLaterMySQLBackend(CONFIGURATION, serverHostName, SERVER_START_TIME_MILLIS);
    }
}

From source file:org.langera.freud.optional.css.cssrule.selector.CssSelectorJdomTest.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());
    cssSelectorJdom = new CssSelectorJdom(null, (Element) context.selectSingleNode("//CLASS"),
            CssSelector.Combinator.DESCENDANT);

}

From source file:org.apache.camel.component.schematron.SchematronComponentTest.java

/**
 * @throws Exception//from   www .  ja v  a 2s  . c  om
 */
@Test
public void testSendBodyAsString() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);

    String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
    template.sendBody("direct:start", payload);
    assertMockEndpointsSatisfied();
    String result = mock.getExchanges().get(0).getIn().getHeader(Constants.VALIDATION_REPORT, String.class);
    assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:failed-assert)", result)).intValue());
    assertEquals(0, Integer.valueOf(Utils.evaluate("count(//svrl:successful-report)", result)).intValue());
}

From source file:edu.usc.goffish.gofs.partition.PartitionTest.java

public void testGMLPartition() throws IOException {
    Path sliceDir = Files.createTempDirectory("slices");
    try {/*w ww  .  jav  a  2 s  . co m*/
        GMLPartition gmlPartition = GMLPartition.parseGML(1, new WCCComponentizer(),
                ClassLoader.getSystemResourceAsStream(TemplateFile), new GMLFileIterable(InstanceFiles));

        // Write the partition
        UUID partitionUUID = UUID.randomUUID();
        ISliceManager sliceManager = SliceManager.create(partitionUUID, new JavaSliceSerializer(),
                new FileStorageManager(sliceDir));
        sliceManager.writePartition(gmlPartition, 1, gmlPartition.size());

        // Read the partition
        sliceManager = SliceManager.create(partitionUUID, new JavaSliceSerializer(),
                new FileStorageManager(sliceDir));
        IPartition actualPartition = sliceManager.readPartition();
        assertNotNull(actualPartition);

        // Test the partition
        comparePartitionTemplates(gmlPartition, actualPartition);
        comparePartitionInstances(actualPartition);

    } finally {
        FileUtils.deleteDirectory(sliceDir.toFile());
    }
}

From source file:org.apache.camel.component.schematron.SchematronEndpointTest.java

@Test
public void testSchematronFileReadFromClassPath() throws Exception {

    String payload = IOUtils.toString(ClassLoader.getSystemResourceAsStream("xml/article-1.xml"));
    Endpoint endpoint = context().getEndpoint("schematron://sch/schematron-1.sch");
    Producer producer = endpoint.createProducer();
    Exchange exchange = new DefaultExchange(context, ExchangePattern.InOut);

    exchange.getIn().setBody(payload);//from w ww  .  j  a v  a 2  s .c  om

    // invoke the component.
    producer.process(exchange);

    String report = exchange.getOut().getHeader(Constants.VALIDATION_REPORT, String.class);
    assertNotNull(report);
}

From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.parser.PrivateEc2TemplateParserTest.java

@Test
public void test() throws Exception {
    String templateFile = "./cfn_templates/WordPress_Single_Instance_With_RDS.template";
    InputStream templateStream = ClassLoader.getSystemResourceAsStream(templateFile);
    PrivateEc2Template template = ParserUtils.mapJson(PrivateEc2Template.class, templateStream);
    assertNotNull(template);//  w  w w. j  a v  a2s .  co  m
    assertNotNull(template.getEC2Instance());
    assertNotNull(template.getEC2Instance().getProperties());
    assertNotNull(template.getEC2Instance().getProperties().getImageId().getValue());
    assertNull(template.getEC2Volume(null));
}

From source file:com.tess4j.rest.Tess4jV1SmokeTest.java

@Test
public void testDoOcr() throws IOException {
    Map<String, String> headers = new HashMap<String, String>();
    headers.put("Accept", MediaType.APPLICATION_JSON_VALUE);
    headers.put("Content-Type", MediaType.APPLICATION_JSON_VALUE);

    Image image = new Image();
    InputStream inputStream = ClassLoader.getSystemResourceAsStream("eurotext.png");
    image.setUserId("arun0009");
    image.setExtension(".png");
    image.setImage(Base64.encodeBase64(IOUtils.toByteArray(inputStream)));
    String response = given().contentType("application/json").headers(headers).when().body(image).expect()
            .statusCode(200).post("http://localhost:8080/ocr/v0.9/upload").asString();
    System.out.println(response);
}

From source file:eu.inmite.apps.smsjizdenka.util.SmsParser.java

private void loadJson(String lang) {
    InputStream is = null;//from w ww.j a va2 s  .  c o  m
    try {
        is = ClassLoader.getSystemResourceAsStream("assets/tickets2.json");
        String json = readResult(is);

        JSONObject o = new JSONObject(json);
        JSONArray array = o.getJSONArray("tickets");

        mCities = new ArrayList<City>();
        for (int i = 0; i < array.length(); i++) {
            final JSONObject cityObject = array.getJSONObject(i);
            City city = new City();
            city.id = cityObject.getInt("id");
            city.city = getStringLocValue(cityObject, lang, "city");
            if (cityObject.has("city_pubtran")) {
                city.cityPubtran = cityObject.getString("city_pubtran");
            }
            city.country = cityObject.getString("country");
            city.currency = cityObject.getString("currency");
            city.dateFormat = cityObject.getString("dateFormat");
            city.identification = cityObject.getString("identification");
            city.lat = cityObject.getDouble("lat");
            city.lon = cityObject.getDouble("lon");
            city.note = getStringLocValue(cityObject, lang, "note");
            city.number = cityObject.getString("number");
            city.pDateFrom = cityObject.getString("pDateFrom");
            city.pDateTo = cityObject.getString("pDateTo");
            city.pHash = cityObject.getString("pHash");
            city.price = cityObject.getDouble("price");
            city.priceNote = getStringLocValue(cityObject, lang, "priceNote");
            city.request = cityObject.getString("request");
            city.validity = cityObject.getInt("validity");
            if (cityObject.has("confirmReq")) {
                city.confirmReq = cityObject.getString("confirmReq");
            }
            if (cityObject.has("confirm")) {
                city.confirm = cityObject.getString("confirm");
            }

            final JSONArray additionalNumbers = cityObject.getJSONArray("additionalNumbers");
            city.additionalNumbers = new String[additionalNumbers.length()];
            for (int j = 0; j < additionalNumbers.length() && j < 3; j++) {
                city.additionalNumbers[j] = additionalNumbers.getString(j);
            }
            mCities.add(city);
        }
    } catch (IOException | JSONException e) {
        throw new RuntimeException("JSON Parsing Error");
    } finally {
        try {
            if (is != null) {
                is.close();
            }
        } catch (IOException e) {
            throw new RuntimeException("JSON Parsing Error");
        }
    }
}

From source file:org.apache.tajo.rule.base.CheckHadoopRuntimeVersionRule.java

public CheckHadoopRuntimeVersionRule() {
    InputStream is = ClassLoader.getSystemResourceAsStream("common-version-info.properties");
    versionInfo = new Properties();
    try {//  www . j  a v  a2  s .c o  m
        versionInfo.load(is);
    } catch (IOException e) {
        LOG.warn(e.getMessage(), e);
    } finally {
        IOUtils.closeStream(is);
    }
}

From source file:rql4j.builder.PageBuilderTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    this.properties = new Properties();
    properties.load(ClassLoader.getSystemResourceAsStream("cms.properties"));
    CmsServer server = new CmsServer(properties.getProperty("cms.test.url"));
    RemoteCallWorker worker = new RemoteCallWorker(server);
    this.command = new RqlCommand(worker);
    AdministrationBuilder loginBuilder = new AdministrationBuilder.Login(
            properties.getProperty("cms.test.user"), properties.getProperty("cms.test.password")).build();
    this.loginGuid = command.getResult(loginBuilder).getLogin().getGuid();
    AdministrationBuilder validateBuilder = new AdministrationBuilder.Validate(
            properties.getProperty("cms.test.project.guid")).build();
    command.getResult(validateBuilder);//from  w ww .ja v a  2  s. c o  m

    // Create TestPage
    PageBuilder.AddNew addNew = new PageBuilder.AddNew();
    String headline = RandomStringUtils.randomAlphabetic(10);
    this.headlines.add(headline);
    addNew.Page(properties.getProperty("cms.test.contentclass.guid"), headline);
    headline = RandomStringUtils.randomAlphabetic(10);
    this.headlines.add(headline);
    addNew.Page(properties.getProperty("cms.test.contentclass.guid"), headline);
    PageBuilder pageBuilder = addNew.build();
    List<Page> createdPages = new ArrayList<Page>();
    List<IoData> ioDataList = command.getResult(pageBuilder).getIoData().getIoDataList();
    for (IoData ioData : ioDataList) {
        createdPages.add(ioData.getPage());
    }
    for (Page page : createdPages) {
        this.pageGuids.add(page.getGuid());
    }
    Assert.assertEquals(2, createdPages.size());
}