Search in sources :

Example 1 with Resource

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

the class ConcatenatingResourceResolverTest method test_concatenation.

@Test
public void test_concatenation() throws IOException {
    Resource testResource = new ClassPathResource("/testResource.txt");
    List<Resource> resources = asList(testResource, testResource, testResource);
    Resource resolvedResource = new ConcatenatingResourceResolver(";".getBytes()).resolveResource(null, "/foo.txt", resources, null);
    assertThat(resolvedResource.getFilename(), is("foo.txt"));
    assertThat(resolvedResource.lastModified(), is(testResource.lastModified()));
    assertThat(resolvedResource.getDescription(), is("Byte array resource [(class path resource [testResource.txt], class path resource [testResource.txt], class path resource [testResource.txt])]"));
    assertThat(copyToByteArray(resolvedResource.getInputStream()), is("Foobar;Foobar;Foobar".getBytes()));
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with Resource

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

the class PreferMinifiedFilteringResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    List<? extends Resource> resources = asList(new ClassPathResource("testResource.txt"), new ClassPathResource("application.properties"));
    new PreferMinifiedFilteringResourceResolver(".min").resolveResource(null, null, resources, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(2));
            assertThat(locations, contains((Resource) new ClassPathResource("testResource.min.txt"), (Resource) new ClassPathResource("application.properties")));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 3 with Resource

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

the class ResourcePatternResolvingResourceResolverTest method test_resolveResource.

@Test
public void test_resolveResource() {
    ResourceResolver resolver = new ResourcePatternResolvingResourceResolver(new PathMatchingResourcePatternResolver(), "classpath:/t*Resource.txt");
    resolver.resolveResource(null, null, null, new ResourceResolverChain() {

        @Override
        public Resource resolveResource(HttpServletRequest request, String requestPath, List<? extends Resource> locations) {
            assertThat(locations.size(), is(1));
            assertThat(locations.get(0).getFilename(), is("testResource.txt"));
            return null;
        }

        @Override
        public String resolveUrlPath(String resourcePath, List<? extends Resource> locations) {
            return null;
        }
    });
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceResolver(org.springframework.web.servlet.resource.ResourceResolver) Resource(org.springframework.core.io.Resource) PathMatchingResourcePatternResolver(org.springframework.core.io.support.PathMatchingResourcePatternResolver) ResourceResolverChain(org.springframework.web.servlet.resource.ResourceResolverChain) Test(org.junit.Test)

Example 4 with Resource

use of org.springframework.core.io.Resource in project cas by apereo.

the class CasCoreBootstrapStandaloneConfiguration method loadEmbeddedYamlOverriddenProperties.

private void loadEmbeddedYamlOverriddenProperties(final Properties props) {
    final Resource resource = resourceLoader.getResource("classpath:/application.yml");
    if (resource != null && resource.exists()) {
        final Map pp = loadYamlProperties(resource);
        if (pp.isEmpty()) {
            LOGGER.debug("No properties were located inside [{}]", resource);
        } else {
            LOGGER.debug("Found settings [{}] in YAML file [{}]", pp.keySet(), resource);
            props.putAll(pp);
        }
    }
}
Also used : Resource(org.springframework.core.io.Resource) FileSystemResource(org.springframework.core.io.FileSystemResource) Map(java.util.Map)

Example 5 with Resource

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

the class ApplicationInitializer method copyLogo.

private void copyLogo(ServletContext servletContext) throws IOException {
    ConfigurationLocator configurationLocator = new ConfigurationLocator();
    Resource logoResource = configurationLocator.getUploadedMifosLogo();
    if (!logoResource.exists()) {
        InputStream defaultLogoStream = servletContext.getResourceAsStream("/pages/framework/images/logo.jpg");
        File logoDir = new File(configurationLocator.getConfigurationDirectory() + File.separator + configurationLocator.getLogoDirectory());
        logoDir.mkdir();
        File logo = new File(logoDir, configurationLocator.getLogoName());
        FileUtils.copyInputStreamToFile(defaultLogoStream, logo);
        logger.info("Copy default logo to: " + logo.getAbsolutePath());
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) File(java.io.File)

Aggregations

Resource (org.springframework.core.io.Resource)1261 ClassPathResource (org.springframework.core.io.ClassPathResource)442 IOException (java.io.IOException)292 Test (org.junit.Test)252 Test (org.junit.jupiter.api.Test)238 File (java.io.File)162 FileSystemResource (org.springframework.core.io.FileSystemResource)144 ArrayList (java.util.ArrayList)139 InputStream (java.io.InputStream)125 UrlResource (org.springframework.core.io.UrlResource)95 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)94 ByteArrayResource (org.springframework.core.io.ByteArrayResource)83 ResourceLoader (org.springframework.core.io.ResourceLoader)60 Properties (java.util.Properties)58 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)55 HashMap (java.util.HashMap)51 InputStreamResource (org.springframework.core.io.InputStreamResource)47 List (java.util.List)40 Map (java.util.Map)35 URL (java.net.URL)34