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

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

Introduction

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

Prototype

InputStream getInputStream() throws IOException;

Source Link

Document

Return an InputStream for the content of an underlying resource.

Usage

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

@Override
protected InputStream getInputStream(Map<String, Object> model, HttpServletRequest request) throws IOException {
    Resource resource = new ClassPathResource("image/Duke.png");
    return resource.getInputStream();
}

From source file:org.pshow.ecm.content.metadata.Bootstrap.java

private PSDef convertToSchame(Resource xml) throws IOException {
    return XmlUtil.toBeanFromStream(xml.getInputStream(), PSDef.class);
}

From source file:com.qdeve.oilprice.FileUtils.java

public String getFileContentAsString(String filename) throws IOException {
    Resource resource = appContext.getResource(filename);
    InputStream inputStream = resource.getInputStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(inputStream, writer, "UTF-8");
    return writer.toString();
}

From source file:io.spring.initializr.test.generator.SourceCodeAssert.java

public SourceCodeAssert equalsTo(Resource expected) {
    try (InputStream stream = expected.getInputStream()) {
        String expectedContent = StreamUtils.copyToString(stream, Charset.forName("UTF-8"));
        assertThat(this.content).describedAs("Content for %s", this.name)
                .isEqualTo(expectedContent.replaceAll("\r\n", "\n"));
    } catch (IOException e) {
        throw new IllegalStateException("Cannot read file", e);
    }/*from  www .j av  a 2 s  .  co  m*/
    return this;
}

From source file:org.apache.nifi.minifi.c2.security.authorization.PrincipalStringAuthorityGranter.java

public PrincipalStringAuthorityGranter(Resource configYaml) throws IOException {
    try (InputStream inputStream = configYaml.getInputStream()) {
        Object yaml = new Yaml().load(inputStream);
        if (!(yaml instanceof Map)) {
            throw new IllegalArgumentException("Expected authority map of Principal -> Authority list");
        }//from  www .  j a v  a 2s .  c  o m
        grantedAuthorityMap = (Map<String, List<String>>) yaml;
    }
}

From source file:com.xyxy.platform.modules.core.security.utils.DigestsTest.java

@Test
public void digestFile() throws IOException {
    Resource resource = new ClassPathResource("/logback.xml");
    byte[] md5result = Digests.md5(resource.getInputStream());
    byte[] sha1result = Digests.sha1(resource.getInputStream());
    System.out.println("md5: " + Encodes.encodeHex(md5result));
    System.out.println("sha1:" + Encodes.encodeHex(sha1result));
}

From source file:nl.flotsam.hamcrest.schema.relaxng.ResourceValidator.java

public boolean validate(Verifier verifier, Resource verifiable) throws SAXException, IOException {
    InputSource source = new InputSource(verifiable.getInputStream());
    source.setSystemId(verifiable.getURI().toASCIIString());
    return new InputSourceValidator().validate(verifier, source);
}

From source file:com.create.application.configuration.ServiceConfiguration.java

@SuppressWarnings("unchecked")
private List<String> getAsStrings(Resource resource) throws IOException {
    try (final Reader reader = new InputStreamReader(resource.getInputStream())) {
        return jacksonObjectMapper.readValue(reader, List.class);
    }/*from  w  w w  .jav  a2 s.  com*/
}

From source file:cherry.foundation.telno.AreaCodeTableFactory.java

/**
 *  ( (6?)??????) ??// w ww.j av  a  2  s  . c  om
 * 
 * @return  ( (6?)??????)
 * @throws InvalidFormatException ????
 * @throws IOException ??
 */
@Override
public Trie<String, Integer> getObject() throws InvalidFormatException, IOException {
    Trie<String, Integer> trie = new PatriciaTrie<>();
    for (Resource r : resources) {
        try (InputStream in = r.getInputStream()) {
            Map<String, Pair<String, String>> map = soumuExcelParser.parse(in);
            for (Map.Entry<String, Pair<String, String>> entry : map.entrySet()) {
                trie.put(entry.getKey(), entry.getValue().getLeft().length());
            }
        }
    }
    return trie;
}

From source file:com.greglturnquist.springagram.fileservice.s3.DatabaseLoader.java

private void loadImage(String filename) throws IOException {
    Resource resource = ctx.getResource("classpath:" + filename);
    this.fileService.saveFile(resource.getInputStream(), resource.getFile().length(), filename);
}