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:nz.co.senanque.parser.InputStreamParserSource.java

public InputStreamParserSource(Resource resource) throws IOException {
    this(resource.getInputStream(), resource.getURI().toString(), 3000);
}

From source file:cherry.foundation.testtool.stub.StubConfigurer.java

public void configure() throws IOException {
    for (Resource r : resources) {
        if (!r.exists()) {
            continue;
        }//from  w ww. j a va  2 s  .co m
        try (InputStream in = r.getInputStream()) {
            Map<Class<?>, Map<String, Object>> map = objectMapper.readValue(in,
                    new TypeReference<LinkedHashMap<Class<?>, Map<String, Object>>>() {
                    });
            for (Map.Entry<Class<?>, Map<String, Object>> entry : map.entrySet()) {
                Multimap<String, Method> methodMap = createMethodMap(entry.getKey().getDeclaredMethods());
                for (Map.Entry<String, Object> ent : entry.getValue().entrySet()) {
                    if (!methodMap.containsKey(ent.getKey())) {
                        continue;
                    }
                    for (Method method : methodMap.get(ent.getKey())) {
                        JavaType type = objectMapper.getTypeFactory()
                                .constructType(method.getGenericReturnType());
                        List<Config> cfglist = parseConfig(ent.getValue());
                        for (Config cfg : cfglist) {
                            Object v = parseValue(cfg, type);
                            if (cfglist.size() == 1) {
                                repository.get(method).alwaysReturn(v);
                            } else {
                                repository.get(method).thenReturn(v);
                            }
                        }
                    }
                }
            }
        }
    }
}

From source file:guru.qas.martini.gherkin.DefaultMixology.java

@Override
public Iterable<Recipe> get(Resource resource) throws IOException {
    checkNotNull(resource, "null Resource");
    TokenMatcher matcher = new TokenMatcher();

    try (InputStream is = resource.getInputStream(); InputStreamReader isr = new InputStreamReader(is)) {
        GherkinDocument document = parser.parse(isr, matcher);
        return getRecipes(resource, document);
    }//  ww  w  .ja  v a 2 s  . c  o  m
}

From source file:com.fns.grivet.controller.AdminDocumentationTest.java

private String payload(String payload) throws IOException {
    Resource r = resolver.getResource(String.format("classpath:%s.json", payload));
    return IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
}

From source file:om.edu.squ.squportal.portlet.dps.role.service.RoleServiceImpl.java

/**
 * /*from   w  w w .  j  av  a 2  s .  c  om*/
 * method name  : getRuleXmlToRoleObject
 * @param xmlFile
 * @return
 * @throws IOException
 * RoleServiceImpl
 * return type  : Object
 * 
 * purpose      : Convert XML to Object (Unmarshalling)
 *
 * Date          :   Feb 8, 2017 2:17:51 PM
 */
public Object getXmlToRoleObject(String xmlFile) throws IOException {
    Resource resource = new ClassPathResource(xmlFile);

    InputStream inputStream = resource.getInputStream();

    return unmarshaller.unmarshal(new StreamSource(inputStream));
}

From source file:fi.helsinki.opintoni.integration.oodi.mock.OodiMockClient.java

public <T> List<T> getOodiResponse(Resource resource, TypeReference<OodiResponse<T>> typeReference) {
    try {//from   w w w .  ja v a  2 s . c  o m
        OodiResponse<T> response = objectMapper.readValue(resource.getInputStream(), typeReference);
        return response.data;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.alfresco.encryption.SpringKeyResourceLoader.java

/**
 * Helper method to switch between application context resource loading or
 * simpler current classloader resource loading.
 *///from  w  ww. ja  v  a 2 s . c om
private InputStream getSafeInputStream(String location) {
    try {
        final InputStream is;
        if (applicationContext != null) {
            Resource resource = applicationContext.getResource(location);
            if (resource.exists()) {
                is = new BufferedInputStream(resource.getInputStream());
            } else {
                // Fall back to conventional loading
                File file = ResourceUtils.getFile(location);
                if (file.exists()) {
                    is = new BufferedInputStream(new FileInputStream(file));
                } else {
                    is = null;
                }
            }
        } else {
            // Load conventionally (i.e. we are in a unit test)
            File file = ResourceUtils.getFile(location);
            if (file.exists()) {
                is = new BufferedInputStream(new FileInputStream(file));
            } else {
                is = null;
            }
        }

        return is;
    } catch (IOException e) {
        return null;
    }
}

From source file:org.jspringbot.keyword.expression.engine.function.SupportedFunctionsManager.java

private void read(Resource resource) throws IOException {
    XStream xstream = new XStream();
    xstream.processAnnotations(Functions.class);

    Functions functions = (Functions) xstream.fromXML(resource.getInputStream());
    for (Function function : functions.getFunctions()) {
        try {//from   w  w  w  . j  a v a  2  s  .  c om
            register(function);
            registered.add(function);
        } catch (Exception e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }
}

From source file:ws.antonov.config.consumer.ConfigClientTest.java

public void testHttpCouchDbConsumption() throws Exception {
    MockHttpClient httpClient = new MockHttpClient();
    final MockHttpMethod method = new MockHttpMethod();
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource json = resolver.getResource("classpath:config.couch");
    method.data = json.getInputStream();

    ConfigClient client = new ProviderBasedConfigClient(
            new HttpConfigProvider("http://domain:port/config/", "{path}", httpClient) {
                @Override//www  .  ja v a  2  s . c o  m
                protected HttpMethod createHttpMethod(String url) {
                    assertEquals(url, "http://domain:port/config/bf4919676664810d86479e997c4b86a5");
                    return method;
                }
            });

    FlatConfigObject config = client.getConfig(FlatConfigObject.class,
            ConfigParamsBuilder.newInstance("path", "bf4919676664810d86479e997c4b86a5").build());
    assertEquals(config.getTimeout(), 10);
    assertEquals(config.getValidate(), false);
    assertEquals(config.getSystemCode(), "101");
}

From source file:com.stehno.sjdbcx.support.SqlResolver.java

private Properties resolve(final Resource resource) {
    // FIXME: properties files need to be cached once loaded.

    final Properties properties = new Properties();

    try (final InputStream input = resource.getInputStream()) {
        properties.load(input);/*from ww w.  java2 s. c  om*/
    } catch (IOException e) {
        log.error("Unable to load property resource ({}): {}", resource, e.getMessage(), e);
    }

    log.trace("Loaded properties file ({}): {}", resource, properties);

    return properties;
}