Search in sources :

Example 51 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project spring-cloud-deployer by spring-cloud.

the class DelegatingResourceLoader method getResource.

@Override
public Resource getResource(String location) {
    try {
        URI uri = new URI(location);
        String scheme = uri.getScheme();
        Assert.notNull(scheme, "a scheme (prefix) is required");
        ResourceLoader loader = this.loaders.get(scheme);
        if (loader == null) {
            if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) {
                loader = new DownloadingUrlResourceLoader();
            } else {
                loader = this.defaultResourceLoader;
            }
        }
        return loader.getResource(location);
    } catch (Exception e) {
        throw new ResourceNotResolvedException(e.getMessage(), e);
    }
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) DefaultResourceLoader(org.springframework.core.io.DefaultResourceLoader) URI(java.net.URI) IOException(java.io.IOException)

Example 52 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project java-function-invoker by projectriff.

the class FunctionConfiguration method delegatingResourceLoader.

@Bean
@ConditionalOnMissingBean(DelegatingResourceLoader.class)
public DelegatingResourceLoader delegatingResourceLoader(MavenProperties mavenProperties) {
    Map<String, ResourceLoader> loaders = new HashMap<>();
    loaders.put(MavenResource.URI_SCHEME, new MavenResourceLoader(mavenProperties));
    return new DelegatingResourceLoader(loaders);
}
Also used : DelegatingResourceLoader(org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) MavenResourceLoader(org.springframework.cloud.deployer.resource.maven.MavenResourceLoader) DelegatingResourceLoader(org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader) HashMap(java.util.HashMap) MavenResourceLoader(org.springframework.cloud.deployer.resource.maven.MavenResourceLoader) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 53 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project core by craftercms.

the class FileSystemContentStoreAdapterTest method setUpTestStoreAdapter.

private void setUpTestStoreAdapter() throws IOException {
    ResourceLoader resourceLoader = mock(ResourceLoader.class);
    when(resourceLoader.getResource(CLASSPATH_STORE_ROOT_FOLDER_PATH)).thenReturn(new ClassPathResource(CLASSPATH_STORE_ROOT_FOLDER_PATH));
    storeAdapter = new FileSystemContentStoreAdapter();
    storeAdapter.setCacheTemplate(cacheTemplate);
    storeAdapter.setResourceLoader(resourceLoader);
    storeAdapter.setDescriptorFileExtension(DESCRIPTOR_FILE_EXTENSION);
    storeAdapter.setMetadataFileExtension(METADATA_FILE_EXTENSION);
    storeAdapter.setPathValidator(new SecurePathValidator("path"));
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) SecurePathValidator(org.craftercms.commons.validation.validators.impl.SecurePathValidator) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 54 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.

the class AudioMetadataExtractionHelperTest method testGetDurationInMillisecondsWAV.

@Test
public void testGetDurationInMillisecondsWAV() throws IOException {
    ResourceLoader resourceLoader = new ClassRelativeResourceLoader(AudioMetadataExtractionHelper.class);
    Resource resource = resourceLoader.getResource("fourteen.wav");
    File audioFile = resource.getFile();
    logger.debug("audioFile: " + audioFile);
    Long durationMs = AudioMetadataExtractionHelper.getDurationInMilliseconds(audioFile);
    assertThat(durationMs, not(nullValue()));
    // 1s
    assertThat(durationMs, is(1000L));
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) Resource(org.springframework.core.io.Resource) File(java.io.File) Test(org.junit.Test)

Example 55 with ResourceLoader

use of org.springframework.core.io.ResourceLoader in project webapp by elimu-ai.

the class AudioMetadataExtractionHelperTest method testGetDurationInMillisecondsMP3.

@Test
public void testGetDurationInMillisecondsMP3() throws IOException {
    ResourceLoader resourceLoader = new ClassRelativeResourceLoader(AudioMetadataExtractionHelper.class);
    Resource resource = resourceLoader.getResource("fourteen.mp3");
    File audioFile = resource.getFile();
    logger.debug("audioFile: " + audioFile);
    Long durationMs = AudioMetadataExtractionHelper.getDurationInMilliseconds(audioFile);
    assertThat(durationMs, not(nullValue()));
    // 1s
    assertThat(durationMs, is(1000L));
}
Also used : ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ClassRelativeResourceLoader(org.springframework.core.io.ClassRelativeResourceLoader) Resource(org.springframework.core.io.Resource) File(java.io.File) Test(org.junit.Test)

Aggregations

ResourceLoader (org.springframework.core.io.ResourceLoader)90 Resource (org.springframework.core.io.Resource)51 Test (org.junit.Test)35 ClassRelativeResourceLoader (org.springframework.core.io.ClassRelativeResourceLoader)34 File (java.io.File)33 DefaultResourceLoader (org.springframework.core.io.DefaultResourceLoader)26 Test (org.junit.jupiter.api.Test)15 IOException (java.io.IOException)9 Environment (org.springframework.core.env.Environment)9 ByteArrayResource (org.springframework.core.io.ByteArrayResource)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)6 FileSystemResource (org.springframework.core.io.FileSystemResource)6 HashMap (java.util.HashMap)5 Configuration (freemarker.template.Configuration)4 Template (freemarker.template.Template)4 InputStream (java.io.InputStream)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 InputStreamReader (java.io.InputStreamReader)3 Properties (java.util.Properties)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3