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

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

Introduction

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

Prototype

@Nullable
String getFilename();

Source Link

Document

Determine a filename for this resource, i.e.

Usage

From source file:com.googlecode.flyway.core.util.ResourceUtils.java

/**
 * Retrieves the location of a resource on disk.
 *
 * @param resource The resource to evaluate.
 * @return The location of the resource on disk.
 *///from  w ww .  ja v  a2s .c  o  m
public static String getResourceLocation(Resource resource) {
    try {
        return resource.getURL().toExternalForm();
    } catch (IOException e) {
        try {
            return resource.getFile().getAbsolutePath();
        } catch (IOException e1) {
            return resource.getFilename();
        }
    }
}

From source file:com.flipkart.phantom.runtime.impl.spring.utils.ConfigFileUtils.java

/**
 * Gets the contents of a <code>Resource</code> in a single String
 * @param resource Resource to be read/*from w  ww.  j  a v a  2 s .  c o m*/
 * @return Contents as a <code>String<code/>
 */
public static String getContents(Resource resource) {
    StringWriter writer = new StringWriter();
    try {
        IOUtils.copy(resource.getInputStream(), writer, "UTF-8");
    } catch (IOException e) {
        LOGGER.error("Exception while reading file " + resource.getFilename(), e);
    }
    return writer.toString();
}

From source file:net.solarnetwork.util.StringMerger.java

/**
 * Merge from a Resource, and return the merged output as a String.
 * //  www .j a  va  2  s.  co  m
 * <p>
 * This method will read the Resource as character data line by line,
 * merging each line as it goes.
 * </p>
 * 
 * @param resource
 *        the resource
 * @param data
 *        the data to merge with
 * @param nullValue
 *        the value to substitute for null data elements
 * @return merged string
 * @throws IOException
 *         if an error occurs
 */
public static String mergeResource(Resource resource, Object data, String nullValue) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Merging " + resource.getFilename() + " with " + data);
    }
    InputStream in = null;
    try {
        in = resource.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder buf = new StringBuilder();
        String oneLine = null;
        while ((oneLine = reader.readLine()) != null) {
            mergeString(oneLine, data, nullValue, buf);
            buf.append("\n");
        }
        return buf.toString();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                // ignore this
            }
        }
    }
}

From source file:org.dspace.servicemanager.spring.ResourceFinder.java

public static File[] getFiles(List<String> paths) {
    List<Resource> rs = makeResources(paths);
    File[] files = new File[rs.size()];
    for (int i = 0; i < rs.size(); i++) {
        Resource r = rs.get(i);
        try {//from   www  .j av a2s  . com
            files[i] = r.getFile();
        } catch (IOException e) {
            throw new RuntimeException("Failed to get file for: " + r.getFilename(), e);
        }
    }
    return files;
}

From source file:org.dspace.servicemanager.spring.ResourceFinder.java

public static File getFile(String path) {
    Resource r = getResource(path);
    File f = null;/*w  w  w  .  j a  v a 2  s .c om*/
    try {
        f = r.getFile();
    } catch (IOException e) {
        throw new RuntimeException("Failed to get file for: " + r.getFilename(), e);
    }
    return f;
}

From source file:org.dspace.servicemanager.spring.ResourceFinder.java

public static InputStream[] getInputStreams(List<String> paths) {
    List<Resource> rs = makeResources(paths);
    InputStream[] streams = new InputStream[rs.size()];
    for (int i = 0; i < rs.size(); i++) {
        Resource r = rs.get(i);
        try {/*from w w w .ja v  a2 s  .  c o  m*/
            streams[i] = r.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException("Failed to get inputstream for: " + r.getFilename(), e);
        }
    }
    return streams;
}

From source file:io.lavagna.web.support.ResourceController.java

private static Map<String, Map<Object, Object>> fromResources(Resource[] resources) throws IOException {

    Pattern extractLanguage = Pattern.compile("^messages_(.*)\\.properties$");

    Map<String, Map<Object, Object>> langs = new HashMap<>();

    String version = Version.version();

    for (Resource res : resources) {
        Matcher matcher = extractLanguage.matcher(res.getFilename());
        matcher.find();//  ww w. ja  va2 s. c  om
        String lang = matcher.group(1);
        Properties p = new Properties();
        try (InputStream is = res.getInputStream()) {
            p.load(is);
        }
        langs.put(lang, new HashMap<>(p));
        langs.get(lang).put("build.version", version);
    }
    return langs;
}

From source file:org.dspace.servicemanager.spring.ResourceFinder.java

public static InputStream getInputStream(String path) {
    Resource r = getResource(path);
    InputStream is = null;/*from ww w  .j  a  v a2 s  . c o m*/
    try {
        is = r.getInputStream();
    } catch (IOException e) {
        throw new RuntimeException("Failed to get inputstream for: " + r.getFilename(), e);
    }
    return is;
}

From source file:org.paxml.util.PaxmlUtils.java

public static String getResourceFile(Resource res) {
    try {// w  w  w.  j  a  va  2 s  .c  om
        return res.getFile().getAbsolutePath();
    } catch (IOException e) {
        return res.getFilename();
    }
}

From source file:me.springframework.di.spring.SinkTypeTest.java

private static Configuration readConfiguration(Resource resource) {
    JavaDocBuilder builder = new JavaDocBuilder();
    builder.addSourceTree(Paths.getFile("src/test/java"));
    Augmentation[] augmentations = { new QDoxAugmentation(builder), new AutowiringAugmentation(builder), };
    SpringConfigurationLoader loader = new SpringConfigurationLoader(augmentations);
    ConfigurableApplicationContext ctxt = new ClassPathXmlApplicationContext(resource.getFilename());
    Configuration configuration = loader.load(ctxt.getBeanFactory());
    return configuration;
}