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:com.jaxio.celerio.maven.plugin.bootstrap.SqlConfInfo.java

public SqlConfInfo(Resource sqlConfInfoAsResource) throws IOException {
    Properties sqlConfInfoAsProperties = new Properties();
    sqlConfInfoAsProperties.load(new InputStreamReader(sqlConfInfoAsResource.getInputStream(), "UTF-8"));
    this.name = sqlConfInfoAsProperties.getProperty("name");
    this.description = sqlConfInfoAsProperties.getProperty("description");
    this.description2 = sqlConfInfoAsProperties.getProperty("description2");
}

From source file:org.craftercms.commons.properties.OverrideProperties.java

/**
 * Checks and starts the reading of the given Resources.
 */// ww w . j a  v  a  2 s .co  m
public void init() {
    for (Resource resource : resources) {
        if (resource.exists()) {
            try (InputStream in = resource.getInputStream()) {
                readPropertyFile(in);
            } catch (IOException ex) {
                log.debug("Unable to load queries from " + resource.getDescription(), ex);
            }
        } else {
            log.info("Query file at {} not found. Ignoring it...", resource.getDescription());
        }
    }
}

From source file:org.meruvian.yama.social.github.GithubService.java

@Override
public User createUser(Connection<?> connection) {
    GitHub gitHub = (GitHub) connection.getApi();
    GitHubUserProfile profile = gitHub.userOperations().getUserProfile();

    String randomUsername = RandomStringUtils.randomAlphanumeric(6);

    User user = new User();
    user.setUsername(StringUtils.join(profile.getName(), randomUsername));
    user.getName().setFirst(profile.getName());
    user.setEmail(profile.getEmail());/*w  ww.  j  a  v a  2s. com*/

    user.setPassword(RandomStringUtils.randomAlphanumeric(8));

    FileInfo fileInfo = new FileInfo();
    try {
        Resource resource = gitHub.restOperations().getForObject(profile.getProfileImageUrl(), Resource.class);
        fileInfo.setDataBlob(resource.getInputStream());
        user.setFileInfo(fileInfo);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

    return user;
}

From source file:org.springframework.data.repository.init.Jackson2ResourceReader.java

public Object readFrom(Resource resource, ClassLoader classLoader) throws Exception {

    InputStream stream = resource.getInputStream();
    JsonNode node = mapper.readerFor(JsonNode.class).readTree(stream);

    if (node.isArray()) {

        Iterator<JsonNode> elements = node.elements();
        List<Object> result = new ArrayList<>();

        while (elements.hasNext()) {
            JsonNode element = elements.next();
            result.add(readSingle(element, classLoader));
        }//from  w w w .jav  a 2  s. c om

        return result;
    }

    return readSingle(node, classLoader);
}

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

public GrantedAuthorityAuthorizer(Resource configYaml) throws IOException {
    try (InputStream inputStream = configYaml.getInputStream()) {
        grantedAuthorityMap = as(Map.class, new Yaml().load(inputStream),
                o -> new IllegalArgumentException("Expected yaml map for root of configuration but was " + o));
    }/*from w  w  w .java  2  s.co m*/
}

From source file:at.gv.egiz.bku.spring.SecurityManagerFactoryBean.java

@Override
public Object getObject() throws Exception {

    SecurityManagerFacade sm = new SecurityManagerFacade();
    sm.setAllowUnmatched(configurationFacade.getAcceptNoMatch());

    Resource policyResource = resourceLoader.getResource(configurationFacade.getPolicyResource());
    sm.init(policyResource.getInputStream());

    return sm;/*  w  w w  .j  a  va 2  s  .c o m*/

}

From source file:com.fns.grivet.service.NamedQueryServiceSelectTest.java

@BeforeEach
public void setUp() throws IOException {
    Resource r = resolver.getResource("classpath:TestType.json");
    String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
    JSONObject payload = new JSONObject(json);
    classRegistryService.register(payload);
}

From source file:org.springframework.rest.documentation.boot.RestDocumentationView.java

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    Resource resource = applicationContext.getResource("classpath:javadoc.json");
    Javadoc javadoc;//w  ww .  j  a va 2s.  co m
    try {
        javadoc = new ObjectMapper().readValue(resource.getInputStream(), Javadoc.class);
    } catch (Exception e) {
        throw new FatalBeanException("Failed to load javadoc JSON", e);
    }

    this.documentationGenerator = new DocumentationGenerator(applicationContext, javadoc);
}

From source file:com.alibaba.cobar.client.router.config.DefaultCobarClientInternalRouterXmlFactoryBean.java

@Override
protected List<InternalRule> loadRulesFromExternal() throws IOException {
    XStream xstream = new XStream();
    xstream.alias("rules", InternalRules.class);
    xstream.alias("rule", InternalRule.class);
    xstream.addImplicitCollection(InternalRules.class, "rules");
    xstream.useAttributeFor(InternalRule.class, "merger");

    List<InternalRule> rules = new ArrayList<InternalRule>();

    if (getConfigLocation() != null) {
        InternalRules internalRules = (InternalRules) xstream.fromXML(getConfigLocation().getInputStream());
        if (!CollectionUtils.isEmpty(internalRules.getRules())) {
            rules.addAll(internalRules.getRules());
        }//from w w  w .ja  va2 s  .  co  m
    }
    if (getConfigLocations() != null && getConfigLocations().length > 0) {
        for (Resource resource : getConfigLocations()) {
            InternalRules internalRules = (InternalRules) xstream.fromXML(resource.getInputStream());
            if (!CollectionUtils.isEmpty(internalRules.getRules())) {
                rules.addAll(internalRules.getRules());
            }
        }
    }

    return rules;
}