当前位置: 首页>>代码示例>>Java>>正文


Java UrlResource类代码示例

本文整理汇总了Java中org.springframework.core.io.UrlResource的典型用法代码示例。如果您正苦于以下问题:Java UrlResource类的具体用法?Java UrlResource怎么用?Java UrlResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UrlResource类属于org.springframework.core.io包,在下文中一共展示了UrlResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveMetadataFromResource

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
/**
 * Resolve metadata from resource.
 *
 * @param service           the service
 * @param metadataResolvers the metadata resolvers
 * @throws Exception the io exception
 */
protected void resolveMetadataFromResource(final SamlRegisteredService service,
                                           final List<MetadataResolver> metadataResolvers) throws Exception {

    final String metadataLocation = service.getMetadataLocation();
    LOGGER.info("Loading SAML metadata from [{}]", metadataLocation);
    final AbstractResource metadataResource = ResourceUtils.getResourceFrom(metadataLocation);

    if (metadataResource instanceof FileSystemResource) {
        resolveFileSystemBasedMetadataResource(service, metadataResolvers, metadataResource);
    }

    if (metadataResource instanceof UrlResource) {
        resolveUrlBasedMetadataResource(service, metadataResolvers, metadataResource);
    }

    if (metadataResource instanceof ClassPathResource) {
        resolveClasspathBasedMetadataResource(service, metadataResolvers, metadataLocation, metadataResource);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:ChainingMetadataResolverCacheLoader.java

示例2: loadAsResource

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
    try {
        Path file = load(filename);
        Resource resource = new UrlResource(file.toUri());
        if(resource.exists() || resource.isReadable()) {
            return resource;
        }
        else {
            throw new StorageFileNotFoundException("Could not read file: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException("Could not read file: " + filename, e);
    }
}
 
开发者ID:Yuiffy,项目名称:file-download-upload-zip-demo,代码行数:17,代码来源:FileSystemStorageService.java

示例3: findOneShouldReturnNotYetFetchedUrl

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void findOneShouldReturnNotYetFetchedUrl() {
	// when
	Mono<Resource> image = imageService.findOneImage("alpha.jpg");

	// then
	then(image).isNotNull();

	StepVerifier.create(image)
		.expectNextMatches(resource -> {
			then(resource.getDescription()).isEqualTo("URL [file:upload-dir/alpha.jpg]");
			then(resource.exists()).isFalse();
			then(resource.getClass()).isEqualTo(UrlResource.class);
			return true;
		})
		.verifyComplete();
}
 
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:18,代码来源:ImageServiceTests.java

示例4: getResourceInputStream

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Override
protected InputStream getResourceInputStream(final Resource resource, final String entityId) throws IOException {
    if (resource instanceof UrlResource && resource.getURL().toExternalForm().toLowerCase().endsWith("/entities/")) {
        final String encodedId = EncodingUtils.urlEncode(entityId);
        final URL url = new URL(resource.getURL().toExternalForm().concat(encodedId));

        LOGGER.debug("Locating metadata input stream for [{}] via [{}]", encodedId, url);
        final HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
        httpcon.setDoOutput(true);
        httpcon.addRequestProperty("Accept", "*/*");
        httpcon.setRequestMethod("GET");
        httpcon.connect();
        return httpcon.getInputStream();
    }
    return ClosedInputStream.CLOSED_INPUT_STREAM;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:DynamicMetadataResolverAdapter.java

示例5: loadAsResource

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Override
public Resource loadAsResource(UserSessionFile userSessionFile) {
    if (userSessionFile == null) {
        throw new StorageException(
            "Cannot retrieve file when userSessionFile is null!");
    }
    try {
        Path file = load(userSessionFile);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new StorageFileNotFoundException(
                "Could not read file: " + userSessionFile.getFilename());

        }
    } catch (MalformedURLException e) {
        throw new StorageFileNotFoundException(
            "Could not read file: " + userSessionFile.getFilename(), e);
    }
}
 
开发者ID:nilshoffmann,项目名称:jmzTab-m,代码行数:22,代码来源:FileSystemStorageService.java

示例6: testGetResourcesString

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
/**
 * Test method for
 * {@link org.springframework.osgi.context.OsgiBundleResourcePatternResolver#getResources(java.lang.String)}.
 */
public void testGetResourcesString() throws Exception {
	Resource[] res;

	try {
		res = resolver.getResources("classpath*:**/*");
		fail("should have thrown exception");
	}
	catch (Exception ex) {
		// expected
	}

	String thisClass = "org/eclipse/gemini/blueprint/io/OsgiBundleResourcePatternResolverTest.class";

	res = resolver.getResources("osgibundle:" + thisClass);
	assertNotNull(res);
	assertEquals(1, res.length);
	assertTrue(res[0] instanceof UrlResource);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:23,代码来源:OsgiBundleResourcePatternResolverTest.java

示例7: fillMediaEntity

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
void fillMediaEntity(MediaEntity mediaEntity) {
    mediaEntity.setResourcePath(resourcePath);
    mediaEntity.setResourceUrl(resourceUrl);
    mediaEntity.setMediaId(mediaId);
    mediaEntity.setMediaUrl(mediaUrl);
    mediaEntity.setCreatedTime(createdTime);
    mediaEntity.setModifiedTime(modifiedTime);
    mediaEntity.setMediaType(mediaType);
    mediaEntity.setStoreType(storeType);
    if (resourcePath != null) {
        mediaEntity.setResource(new FileSystemResource(resourcePath));
    } else if (resourceUrl != null) {
        try {
            mediaEntity.setResource(new UrlResource(URI.create(resourceUrl)));
        } catch (MalformedURLException e) {
            logger.error(e.getMessage(), e);
        }
    }
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:20,代码来源:MapDbWxMediaStore.java

示例8: loadAsResource

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Override
public Resource loadAsResource(String filename) {
    try {
        Path file = this.rootLocation.resolve(filename);
        Resource resource = new UrlResource(file.toUri());
        if (resource.exists() || resource.isReadable()) {
            return resource;
        } else {
            throw new UploadFileNotFoundException(
                    "Could not read file: " + filename);

        }
    } catch (MalformedURLException e) {
        throw new UploadFileNotFoundException("Could not read file: " + filename, e);
    }
}
 
开发者ID:itdl,项目名称:AIweb,代码行数:17,代码来源:UploadServiceImpl.java

示例9: loadFactoryNames

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
/**
 * Load the fully qualified class names of factory implementations of the
 * given type from {@value #FACTORIES_RESOURCE_LOCATION}, using the given
 * class loader.
 * @param factoryClass the interface or abstract class representing the factory
 * @param classLoader the ClassLoader to use for loading resources; can be
 * {@code null} to use the default
 * @see #loadFactories
 * @throws IllegalArgumentException if an error occurs while loading factory names
 */
public static List<String> loadFactoryNames(Class<?> factoryClass, ClassLoader classLoader) {
	String factoryClassName = factoryClass.getName();
	try {
		Enumeration<URL> urls = (classLoader != null ? classLoader.getResources(FACTORIES_RESOURCE_LOCATION) :
				ClassLoader.getSystemResources(FACTORIES_RESOURCE_LOCATION));
		List<String> result = new ArrayList<String>();
		while (urls.hasMoreElements()) {
			URL url = urls.nextElement();
			Properties properties = PropertiesLoaderUtils.loadProperties(new UrlResource(url));
			String factoryClassNames = properties.getProperty(factoryClassName);
			result.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(factoryClassNames)));
		}
		return result;
	}
	catch (IOException ex) {
		throw new IllegalArgumentException("Unable to load [" + factoryClass.getName() +
				"] factories from location [" + FACTORIES_RESOURCE_LOCATION + "]", ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:SpringFactoriesLoader.java

示例10: testGenericListProperty

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericListProperty() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);

	List<String> input = new ArrayList<String>();
	input.add("http://localhost:8080");
	input.add("http://localhost:9090");
	rbd.getPropertyValues().add("resourceList", input);

	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
	assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:BeanFactoryGenericsTests.java

示例11: testGenericSetListConstructor

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericSetListConstructor() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);

	Set<String> input = new HashSet<String>();
	input.add("4");
	input.add("5");
	List<String> input2 = new ArrayList<String>();
	input2.add("http://localhost:8080");
	input2.add("http://localhost:9090");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input2);

	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertTrue(gb.getIntegerSet().contains(new Integer(4)));
	assertTrue(gb.getIntegerSet().contains(new Integer(5)));
	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
	assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:BeanFactoryGenericsTests.java

示例12: testGenericSetListConstructorWithAutowiring

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericSetListConstructorWithAutowiring() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerSingleton("integer1", new Integer(4));
	bf.registerSingleton("integer2", new Integer(5));
	bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
	bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));

	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
	rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertTrue(gb.getIntegerSet().contains(new Integer(4)));
	assertTrue(gb.getIntegerSet().contains(new Integer(5)));
	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
	assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:BeanFactoryGenericsTests.java

示例13: testGenericMapResourceConstructor

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericMapResourceConstructor() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);

	Map<String, String> input = new HashMap<String, String>();
	input.put("4", "5");
	input.put("6", "7");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
	rbd.getConstructorArgumentValues().addGenericArgumentValue("http://localhost:8080");

	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
	assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:BeanFactoryGenericsTests.java

示例14: testGenericSetListFactoryMethod

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericSetListFactoryMethod() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
	rbd.setFactoryMethodName("createInstance");

	Set<String> input = new HashSet<String>();
	input.add("4");
	input.add("5");
	List<String> input2 = new ArrayList<String>();
	input2.add("http://localhost:8080");
	input2.add("http://localhost:9090");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input2);

	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertTrue(gb.getIntegerSet().contains(new Integer(4)));
	assertTrue(gb.getIntegerSet().contains(new Integer(5)));
	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
	assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:BeanFactoryGenericsTests.java

示例15: testGenericMapResourceFactoryMethod

import org.springframework.core.io.UrlResource; //导入依赖的package包/类
@Test
public void testGenericMapResourceFactoryMethod() throws MalformedURLException {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
	rbd.setFactoryMethodName("createInstance");

	Map<String, String> input = new HashMap<String, String>();
	input.put("4", "5");
	input.put("6", "7");
	rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
	rbd.getConstructorArgumentValues().addGenericArgumentValue("http://localhost:8080");

	bf.registerBeanDefinition("genericBean", rbd);
	GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");

	assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
	assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
	assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:BeanFactoryGenericsTests.java


注:本文中的org.springframework.core.io.UrlResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。