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:com.turbospaces.monitor.services.GroupDiscoveryService.java

public synchronized JChannel connect(final String group, final byte[] bytes) throws Exception {
    JChannel jChannel = channels.get(group);
    if (jChannel == null || bytes != null) {
        ClassPathResource resource = new ClassPathResource("udp-largecluster.xml");
        InputStream inputStream = resource.getInputStream();
        jChannel = new JChannel(inputStream);
        inputStream.close();/*from   w  w  w .  j av  a  2s.  c o m*/
        if (bytes != null) {
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
            jChannel = new JChannel(byteArrayInputStream);
            byteArrayInputStream.close();
        }
        jChannel.setDiscardOwnMessages(true);
        ProtocolStack protocolStack = jChannel.getProtocolStack();
        protocolStack.getTransport().setValue("enable_diagnostics", false);
        logger.info("joining network group {}", group);
        jChannel.connect(group);
        channels.put(group, jChannel);
    }

    return jChannel;
}

From source file:com.marklogic.samplestack.integration.service.MarkLogicIntegrationIT.java

protected JsonNode getTestJson(String testPath) {
    ClassPathResource r = new ClassPathResource(testPath);
    try {//from  w  w  w .  j a  v  a2s .c  om
        return mapper.readValue(r.getInputStream(), JsonNode.class);
    } catch (IOException e) {
        throw new SamplestackIOException(e);
    }
}

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

@Override
public GramModel getGramModel() throws Exception {
    ClassPathResource cpRes = locateDictionaryClasspathResource();
    return GramModelDeserializer.from(cpRes.getInputStream(), cpRes.getURL().toString());
}

From source file:biz.c24.io.spring.integration.samples.transform.TransformTest.java

byte[] loadCsvBytes() throws Exception {

    ClassPathResource resource = new ClassPathResource("valid-1.txt", this.getClass());
    byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream());

    return valid1;
}

From source file:io.bosh.client.AbstractDirectorTest.java

protected String payload(String filename) {
    ClassPathResource resource = new ClassPathResource(filename);
    try {//from ww w  . ja  v a  2s.c o m
        return FileCopyUtils.copyToString(new InputStreamReader(resource.getInputStream()));
    } catch (IOException e) {
        throw new RuntimeException("TEST SETUP ERROR: unable to find test resources file with name " + filename,
                e);
    }

}

From source file:com.acme.TopTagsTupleTest.java

@Test
public void tags() throws IOException {

    final Broadcaster<Object> broadcaster = SerializedBroadcaster.create();

    Processor processor = new TopTags(1, 10);
    Stream<?> outputStream = processor.process(broadcaster);

    outputStream.consume(new Consumer<Object>() {
        @Override/*from  www  . j a v  a 2 s  . com*/
        public void accept(Object o) {
            System.out.println("processed : " + o);
        }
        //TODO - expect
        //            processed : {"id":"55786760-7472-065d-8e62-eb83260948a4","timestamp":1422399628134,"hashtag":"AndroidGames","count":1}
        //            processed : {"id":"bd99050f-abfa-a239-c09a-f2fe721daafb","timestamp":1422399628182,"hashtag":"Android","count":1}
        //            processed : {"id":"10ce993c-fd57-322d-efa1-16f810918187","timestamp":1422399628184,"hashtag":"GameInsight","count":1}
    });

    ClassPathResource resource = new ClassPathResource("tweets.json");
    Scanner scanner = new Scanner(resource.getInputStream());
    while (scanner.hasNext()) {
        String tweet = scanner.nextLine();
        broadcaster.onNext(tweet);
        //simulateLatency();
    }
    //System.in.read();

}

From source file:org.terasoluna.gfw.functionaltest.app.download.DownloadTest.java

@Test
public void test01_01_fileDownload() throws IOException {
    ResponseEntity<byte[]> response = restTemplate.getForEntity(applicationContextUrl + "/download/1_1",
            byte[].class);
    ClassPathResource images = new ClassPathResource("/image/Duke.png");

    byte[] expected = StreamUtils.copyToByteArray(images.getInputStream());

    HttpHeaders headers = response.getHeaders();
    System.out.println("test01_01_fileDownload: X-Track=" + headers.getFirst("X-Track"));
    assertThat(headers.getFirst("Content-Disposition"), is("attachment; filename=Duke.png"));

    MediaType contentType = headers.getContentType();
    assertThat(contentType.getType(), is("image"));
    assertThat(contentType.getSubtype(), is("png"));

    assertThat(response.getBody(), is(expected));
}

From source file:demo.service.RemoteVehicleDetailsServiceWireMockTest.java

private byte[] getClassPathResource(String path) throws IOException {
    ClassPathResource resource = new ClassPathResource(path, getClass());
    return FileCopyUtils.copyToByteArray(resource.getInputStream());
}

From source file:org.cleverbus.admin.web.changes.ChangesController.java

@RequestMapping(value = CHANGES_URI, method = RequestMethod.GET)
@ResponseBody/* w w w  .j  a  v a 2s.  co  m*/
public String getChangesContent() throws IOException {
    ClassPathResource resource = new ClassPathResource("changes.txt");

    // add end of lines
    String resStr = "";
    List<String> lines = IOUtils.readLines(resource.getInputStream(), "utf-8");
    for (String line : lines) {
        resStr += line;
        resStr += "<br/>\n";
    }

    return resStr;
}

From source file:org.springmodules.cache.provider.CacheManagerFactoryBeanTests.java

public void testGetConfigProperties() throws Exception {
    String path = PathUtils.getPackageNameAsPath(getClass()) + "/cacheProvider.properties";

    ClassPathResource resource = new ClassPathResource(path);
    Properties expected = new Properties();
    expected.load(resource.getInputStream());

    factoryBean.setConfigLocation(new ClassPathResource(path));
    assertEquals(expected, factoryBean.getConfigProperties());
}