當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。