Search in sources :

Example 11 with Resource

use of org.springframework.core.io.Resource in project head by mifos.

the class PPISurveyLocatorImpl method getPPIUploadFileForCountry.

@Override
public String getPPIUploadFileForCountry(String country) {
    try {
        String fileName = getPPIXmlFileName(country);
        Resource resource = this.resourceLoader.getResource(resolvePath());
        return getPPIFilePath(fileName, resource.getFile());
    } catch (IOException e) {
        throw new SystemException(FETCH_PPI_COUNTRY_XML_FAILED, e);
    }
}
Also used : SystemException(org.mifos.framework.exceptions.SystemException) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException)

Example 12 with Resource

use of org.springframework.core.io.Resource in project head by mifos.

the class MifosResourceUtilTest method testGetResources.

@Test
public void testGetResources() throws IOException {
    Resource[] found = MifosResourceUtil.getClassPathResourcesAsResources("org/mifos/core/resources/included/**/*.xml");
    assertEquals(2, found.length);
    for (Resource resource : found) {
        String f = resource.getFilename();
        if (!"y.xml".equals(f) && !"z.xml".equals(f)) {
            fail(resource + " should not have been returned");
        }
    }
}
Also used : Resource(org.springframework.core.io.Resource) Test(org.junit.Test)

Example 13 with Resource

use of org.springframework.core.io.Resource in project head by mifos.

the class ConfigurationLocator method getCustomFilePath.

/**
     * Will not throw an exception if the file is not found. This method may be
     * used to find files in cases where we don't care if the file cannot be
     * found.
     * @throws IOException
     */
@SuppressWarnings("PMD")
public // TODO It may be clearer if this returned an URI or URL instead of a String?
String getCustomFilePath(String filename) throws IOException {
    String returnValue = filename;
    LOGGER.info("Checking existance of : " + filename);
    Resource configFile = getResource(filename);
    if (configFile != null && configFile.exists()) {
        returnValue = configFile.getURL().toExternalForm();
        LOGGER.info("Custom configuration file exists : " + returnValue);
    }
    return returnValue;
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) FileSystemResource(org.springframework.core.io.FileSystemResource) Resource(org.springframework.core.io.Resource)

Example 14 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class ResourceUtils method getChildFiles.

private static List<String> getChildFiles(Resource resource) throws IOException {
    Resource[] children = new PathMatchingResourcePatternResolver().getResources(resource.getURL() + "/**");
    List<String> childFiles = new ArrayList<>();
    for (Resource child : children) {
        if (!child.getFile().isDirectory()) {
            childFiles.add(absolutePath(child));
        }
    }
    return childFiles;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Example 15 with Resource

use of org.springframework.core.io.Resource in project spring-boot by spring-projects.

the class ResourceUtils method getUrlsFromPrefixedWildcardPath.

private static List<String> getUrlsFromPrefixedWildcardPath(String path, ClassLoader classLoader) throws IOException {
    Resource[] resources = new PathMatchingResourcePatternResolver(new FileSearchResourceLoader(classLoader)).getResources(path);
    List<String> result = new ArrayList<>();
    for (Resource resource : resources) {
        if (resource.exists()) {
            if (resource.getURI().getScheme().equals("file")) {
                if (resource.getFile().isDirectory()) {
                    result.addAll(getChildFiles(resource));
                    continue;
                }
            }
            result.add(absolutePath(resource));
        }
    }
    return result;
}
Also used : UrlResource(org.springframework.core.io.UrlResource) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ArrayList(java.util.ArrayList) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver)

Aggregations

Resource (org.springframework.core.io.Resource)541 Test (org.junit.Test)248 ClassPathResource (org.springframework.core.io.ClassPathResource)217 IOException (java.io.IOException)86 FileSystemResource (org.springframework.core.io.FileSystemResource)67 File (java.io.File)60 UrlResource (org.springframework.core.io.UrlResource)60 ArrayList (java.util.ArrayList)49 ByteArrayResource (org.springframework.core.io.ByteArrayResource)46 InputStream (java.io.InputStream)33 InputStreamResource (org.springframework.core.io.InputStreamResource)31 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)24 URL (java.net.URL)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)18 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)16 ServletContextResource (org.springframework.web.context.support.ServletContextResource)16 URI (java.net.URI)15 ResourceLoader (org.springframework.core.io.ResourceLoader)15 HashMap (java.util.HashMap)13 LinkedHashSet (java.util.LinkedHashSet)13