Example usage for org.springframework.core.io ClassPathResource getInputStream

List of usage examples for org.springframework.core.io ClassPathResource getInputStream

Introduction

In this page you can find the example usage for org.springframework.core.io ClassPathResource getInputStream.

Prototype

@Override
public InputStream getInputStream() throws IOException 

Source Link

Document

This implementation opens an InputStream for the given class path resource.

Usage

From source file:org.openmrs.module.dhisreport.api.DHIS2ReportingServiceDAOTest.java

@Before
public void before() throws Exception {
    _default = new Disaggregation();
    _default.setName("default");
    _default.setCode("default");

    service = Context.getService(DHIS2ReportingService.class);
    ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml");
    service.unMarshallandSaveReportTemplates(resource.getInputStream());
}

From source file:cloudfoundry.norouter.f5.F5Initializer.java

ST sessionAffinityIRule() throws IOException {
    final ClassPathResource resource = new ClassPathResource("templates/irules/session-affinity.tcl.st");
    final String template = StreamUtils.copyToString(resource.getInputStream(), StandardCharsets.UTF_8);
    return new ST(template);
}

From source file:com.oreilly.rdf.tenuki.TestChangeLoader.java

@Test
public void testApplyChangesetFile() throws Exception {
    ClassPathResource changesetResource = new ClassPathResource("changeset.xml");
    Changeset changeset = new InputStreamChangeset(changesetResource.getInputStream());

    ChangesetHandler handler = new ChangesetHandler(model);
    handler.applyChangeset(changeset);/* w  w  w  . ja  v  a 2 s .  co  m*/
    Resource testingResource = model.createResource(TESTING_RESOURCE_URI);
    Statement result = testingResource.getProperty(DC.title);
    Literal title = result.getLiteral();
    Assert.assertEquals(AFTER_TITLE, title.getLexicalForm());

}

From source file:org.openmrs.module.dhisreport.api.DHIS2ReportingServiceDAOTest.java

@Ignore
@Test/* w w w . ja  va  2 s.com*/
public void marshallerTest() throws Exception {
    ClassPathResource resource = new ClassPathResource("templates_ethiopia.xml");
    service.unMarshallandSaveReportTemplates(resource.getInputStream());

    ReportTemplates rds = service.getReportTemplates();
    assertEquals(3, rds.getDataElements().size());
    assertEquals(3, rds.getDisaggregations().size());
    assertEquals(2, rds.getReportDefinitions().size());

    service.marshallReportTemplates(System.out, rds);
}

From source file:org.springframework.sync.JsonPatchTest.java

private Patch readJsonPatch(String jsonPatchFile) throws IOException, JsonParseException, JsonMappingException {
    ClassPathResource resource = new ClassPathResource(jsonPatchFile);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readValue(resource.getInputStream(), JsonNode.class);
    Patch patch = new JsonPatchPatchConverter().convert(node);
    return patch;
}

From source file:com.oembedler.moon.graphql.test.GenericComputationDelaySchemaParserTest.java

public String getClasspathResourceAsString(final String resourceName) {
    String resourceAsString = null;

    ClassPathResource classPathResource = new ClassPathResource(resourceName);
    try (InputStream is = classPathResource.getInputStream()) {
        resourceAsString = StreamUtils.copyToString(is, Charset.forName("UTF-8"));
    } catch (IOException e) {
        e.printStackTrace();// w ww  . j a v  a2s  .c  o m
    }
    return resourceAsString;
}

From source file:magoffin.matt.sobriquet.sendmail.test.SendmailAliasFileParserTests.java

@Test
public void testParseSampleFile() throws IOException {
    ClassPathResource r = new ClassPathResource("aliases.txt", getClass());
    InputStreamReader in = null;/*from  w w  w.ja va 2 s  . c  o m*/
    try {
        in = new InputStreamReader(r.getInputStream());
        SendmailAliasFileParser parser = new SendmailAliasFileParser(in);
        int count = 0;
        for (Alias a : parser) {
            Assert.assertEquals("Alias " + count, SAMPLE_ALIASES[count][0], a.getAlias());
            Assert.assertEquals("Actual " + count, SAMPLE_ALIASES[count][1], a.getActual());
            Assert.assertEquals("Acutal count " + count, 1, a.getActuals().size());
            count++;
        }
        Assert.assertEquals("Parsed count", SAMPLE_ALIASES.length, count);
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

From source file:org.springframework.data.rest.webmvc.json.patch.JsonPatchTest.java

private Patch readJsonPatch(String jsonPatchFile) throws IOException, JsonParseException, JsonMappingException {
    ClassPathResource resource = new ClassPathResource(jsonPatchFile, getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode node = mapper.readValue(resource.getInputStream(), JsonNode.class);
    Patch patch = new JsonPatchPatchConverter().convert(node);
    return patch;
}

From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.simple.RemoteClassProvider.java

@Override
public void onMessage(Message message) {
    String className = null;/*  w  ww  . ja  v a  2s  .c om*/

    try {
        className = ((ClassRequest) ((ObjectMessage) message).getObject()).className;

        log.fine("Message received:" + className);

        // we expect sender to specify the query he's waiting response into the JMSReplyTo
        Destination destination = message.getJMSReplyTo();
        UUID correlationId = UUID.fromString(message.getJMSCorrelationID());

        // preparing class bytecode.
        byte[] bytecode = null;

        try {
            String classPath = className.replace('.', '/') + ".class";//TODO: use utils.
            InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream(classPath);

            // If the class cannot be found, attempt to find a resource with the requested name
            if (is == null) {
                try {
                    ClassPathResource resource = new ClassPathResource(className);
                    if (resource.exists()) {
                        is = resource.getInputStream();
                    }
                } catch (IOException e) {
                    // Ignore
                }
            }

            if (is == null)
                log.severe(String.format("Requested class %s was not found.", className));
            else
                bytecode = RemoteClassLoaderUtils.getByteArray(is);

        } catch (Exception ex) {
            log.severe("Failed to provide required class " + className + ": " + ex.toString());
            ex.printStackTrace();
        } finally {
            mq.respond(new ClassResponse(bytecode), destination, correlationId);
        }

    } catch (JMSException e) {
        log.severe("Failed to process message (" + className + "): " + e.toString());
        e.printStackTrace();
    }
}

From source file:com.textocat.textokit.morph.opencorpora.OpencorporaMorphDictionaryAPI.java

@Override
public CachedResourceTuple<MorphDictionary> getCachedInstance() throws Exception {
    ClassPathResource cpRes = locateDictionaryClasspathResource();
    CachedDictionaryDeserializer.GetDictionaryResult gdr = CachedDictionaryDeserializer.getInstance()
            .getDictionary(cpRes.getURL(), cpRes.getInputStream());
    return new CachedResourceTuple<>(gdr.cacheKey, gdr.dictionary);
}