Example usage for org.springframework.util ResourceUtils getFile

List of usage examples for org.springframework.util ResourceUtils getFile

Introduction

In this page you can find the example usage for org.springframework.util ResourceUtils getFile.

Prototype

public static File getFile(URI resourceUri) throws FileNotFoundException 

Source Link

Document

Resolve the given resource URI to a java.io.File , i.e.

Usage

From source file:org.springframework.integration.flow.config.FlowUtils.java

/**
 * Read the flow documentation resource into a String if it exists. The
 * location is classpath:META-INF/spring/integration/flows/[flowId]/flow.doc
 * @param flowId the flow id/*from   w w  w.  j av a2  s .c  om*/
 * @return the documentation
 */
public static String getDocumentation(String flowId) {

    String path = String.format("classpath:META-INF/spring/integration/flows/%s/flow.doc", flowId);

    try {
        File file = ResourceUtils.getFile(path);

        BufferedReader br = new BufferedReader(new FileReader(file));

        String line;
        StringBuilder result = new StringBuilder();
        while ((line = br.readLine()) != null) {
            result.append(line).append("\n");
        }

        br.close();

        return result.toString();

    } catch (FileNotFoundException e) {
        return "no help available";
    } catch (IOException e) {
        e.printStackTrace();
        return "no help available";
    }
}

From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalFileTestExecutionListener.java

@SuppressWarnings("unchecked")
private OwncloudProperties loadProperties(String[] activeProfiles) throws IOException {
    Yaml yaml = new Yaml();
    for (String activeProfile : activeProfiles) {
        String propertyFilename = PROPERTY_FILE_PREFIX + activeProfile + PROPERTY_FILE_SUFFIX;
        log.debug("Try to parse File {} with SnakeYaml", propertyFilename);
        File propertyFile = ResourceUtils.getFile(propertyFilename);
        try (InputStream input = new FileInputStream(propertyFile)) {
            Map<String, Object> properties = ((Map<String, Map<String, Object>>) yaml.load(input))
                    .get("owncloud");
            OwncloudProperties owncloudProperties = new OwncloudLocalProperties();
            for (Entry<String, Object> property : properties.entrySet()) {
                switch (property.getKey()) {
                case "location":
                    owncloudProperties.setLocation((String) property.getValue());
                    break;
                case "user-service.enable-modifications":
                case "userService.enable-modifications":
                case "user-service.enableModifications":
                case "userService.enableModifications":
                    if (owncloudProperties.getUserService() == null) {
                        owncloudProperties.setUserService(new OwncloudProperties.UserService());
                    }// www .  j  a v a2 s.c o m
                    owncloudProperties.getUserService().setEnableModifications((Boolean) property.getValue());
                    break;
                }
            }
            Validate.notNull(owncloudProperties.getLocation());
            return owncloudProperties;
        }
    }
    return null;
}

From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalFileTestExecutionListener.java

private void copyResource(OwncloudProperties owncloudProperties) throws IOException {
    File original = ResourceUtils.getFile(ORIGINAL_RESOURCE);
    File target = ResourceUtils.getFile(owncloudProperties.getLocation());
    target.deleteOnExit();/*from ww  w . j ava  2  s . c o  m*/
    try (InputStream input = new BufferedInputStream(new FileInputStream(original));
            OutputStream output = new BufferedOutputStream(new FileOutputStream(target))) {
        IOUtils.copy(input, output);
    }
}