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:fr.mby.saml2.sp.impl.helper.SecurityHelper.java

public static byte[] readBytesFromFilePath(final Resource resource) throws IOException {
    byte[] keyBytes = null;

    final InputStream keyStream = resource.getInputStream();
    keyBytes = IOUtils.toByteArray(keyStream);

    return keyBytes;
}

From source file:org.jspringbot.spring.KeywordUtils.java

/**
 * Retrieves the given keyword's description.
 *
 * @param keyword keyword name/*from  w ww. j  ava2  s  .  co m*/
 * @param context Spring application context
 * @param beanMap keyword name to bean name mapping
 * @return the documentation string of the given keyword, or empty string if unavailable.
 */
public static String getDescription(String keyword, ApplicationContext context, Map<String, String> beanMap) {
    KeywordInfo keywordInfo = getKeywordInfo(keyword, context, beanMap);

    if (keywordInfo == null) {
        return "";
    }

    String desc = keywordInfo.description();

    if (desc.startsWith("classpath:")) {
        try {
            ResourceEditor editor = new ResourceEditor();
            editor.setAsText(desc);
            Resource r = (Resource) editor.getValue();

            return IOUtils.toString(r.getInputStream());
        } catch (Exception ignored) {
        }
    }

    return desc;
}

From source file:org.springframework.hateoas.alps.JacksonSerializationTests.java

private static String read(Resource resource) throws IOException {

    Scanner scanner = null;/*from  w  ww.jav  a  2  s. c om*/

    try {

        scanner = new Scanner(resource.getInputStream());
        StringBuilder builder = new StringBuilder();

        while (scanner.hasNextLine()) {

            builder.append(scanner.nextLine());

            if (scanner.hasNextLine()) {
                builder.append("\n");
            }
        }

        return builder.toString();

    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:com.aw.core.business.AWContext.java

public static void initBuildInfo() {
    buildNumber = "<Undefined>";
    java.util.Properties props = new java.util.Properties();
    //        java.net.URL url = ClassLoader.getSystemResource("version.properties");
    Resource r = new ClassPathResource("version.properties");
    try {/*from  w w w  .j a  va  2 s  .co  m*/
        props.load(r.getInputStream());
        buildNumber = (String) props.get("version");
    } catch (Throwable e) {
        logger.warn("Error loading project version Info", e);
        e.printStackTrace();
    }

}

From source file:org.springframework.hateoas.alps.JacksonSerializationTest.java

private static String read(Resource resource) throws IOException {

    Scanner scanner = null;/*from   w  w  w.j a  v  a  2  s. co  m*/

    try {

        scanner = new Scanner(resource.getInputStream());
        StringBuilder builder = new StringBuilder();

        while (scanner.hasNextLine()) {

            builder.append(scanner.nextLine());

            if (scanner.hasNextLine()) {
                builder.append(System.getProperty("line.separator"));
            }
        }

        return builder.toString();

    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}

From source file:org.dkpro.similarity.experiments.sts2013baseline.util.Features2Arff.java

public static void toArffFile(Mode mode, Dataset... datasets) throws IOException {
    for (Dataset dataset : datasets) {
        String path = GOLDSTANDARD_DIR + "/" + mode.toString().toLowerCase() + "/STS.gs." + dataset.toString()
                + ".txt";

        PathMatchingResourcePatternResolver r = new PathMatchingResourcePatternResolver();
        Resource res = r.getResource(path);

        toArffFile(mode, dataset, res.getInputStream());
    }/*from  w  ww.  j a va2s. c  o  m*/
}

From source file:gov.nih.nci.cabig.ctms.tools.configuration.DefaultConfigurationProperties.java

private static Properties loadDetails(Resource resource) {
    Properties details = new Properties();
    try {/*from   ww w.ja  va 2s .c om*/
        details.load(resource.getInputStream());
    } catch (IOException e) {
        throw new CommonsSystemException("Failed to load property details from " + resource, e);
    }
    return details;
}

From source file:com.sfxie.extension.spring4.properties.PropertiesLoaderUtils.java

/**
 * Fill the given properties from the given resource (in ISO-8859-1 encoding).
 * @param props the Properties instance to fill
 * @param resource the resource to load from
 * @throws IOException if loading failed
 *//*ww  w. jav  a 2 s .  c  om*/
public static void fillProperties(Properties props, Resource resource) throws IOException {
    InputStream is = resource.getInputStream();
    try {
        String filename = resource.getFilename();
        if (filename != null && filename.endsWith(XML_FILE_EXTENSION)) {
            props.loadFromXML(is);
        } else {
            props.load(is);
        }
    } finally {
        is.close();
    }
}

From source file:com.opengamma.examples.simulated.DBTestUtils.java

public static Properties loadProperties(String configResourceLocation) throws IOException {
    Resource resource = ResourceUtils.createResource(configResourceLocation);
    Properties props = new Properties();
    props.load(resource.getInputStream());

    String nextConfiguration = props.getProperty("MANAGER.NEXT.FILE");
    if (nextConfiguration != null) {
        resource = ResourceUtils.createResource(nextConfiguration);
        Properties parentProps = new Properties();
        parentProps.load(resource.getInputStream());
        for (String key : props.stringPropertyNames()) {
            parentProps.put(key, props.getProperty(key));
        }/*from  ww  w  . j a  v a  2 s.co  m*/
        props = parentProps;
    }

    for (String key : props.stringPropertyNames()) {
        s_logger.debug("\t{}={}", key, props.getProperty(key));
    }

    return props;
}

From source file:kr.co.skysoft.framework.taglib.JSR303JSCodebaseTag.java

/**
 * Returns a <code>Reader</code> for accessing the JavaScript codebase used by the
 * translated validation rules.//from  ww  w  .  j a v a 2 s .  c o m
 *
 * @return a Reader for accessing the JavaScript codebase used by the translated validation rules
 * @throws java.io.IOException
 */
public static Reader getCodebaseReader() throws IOException {
    Resource codebaseResource = new ClassPathResource("jsr303js-codebase.js");
    return new InputStreamReader(codebaseResource.getInputStream());
}