本文整理汇总了Java中org.springframework.core.io.FileSystemResource类的典型用法代码示例。如果您正苦于以下问题:Java FileSystemResource类的具体用法?Java FileSystemResource怎么用?Java FileSystemResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileSystemResource类属于org.springframework.core.io包,在下文中一共展示了FileSystemResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGoogleAppsPublicKey
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
/**
* Create the public key.
*
* @throws Exception if key creation ran into an error
*/
protected void createGoogleAppsPublicKey() throws Exception {
if (!isValidConfiguration()) {
LOGGER.debug("Google Apps public key bean will not be created, because it's not configured");
return;
}
final PublicKeyFactoryBean bean = new PublicKeyFactoryBean();
if (this.publicKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else if (this.publicKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
} else {
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
}
bean.setAlgorithm(this.keyAlgorithm);
LOGGER.debug("Loading Google Apps public key from [{}] with key algorithm [{}]",
bean.getResource(), bean.getAlgorithm());
bean.afterPropertiesSet();
LOGGER.debug("Creating Google Apps public key instance via [{}]", this.publicKeyLocation);
this.publicKey = bean.getObject();
}
示例2: resolveMetadataFromResource
import org.springframework.core.io.FileSystemResource; //导入依赖的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);
}
}
示例3: CRLDistributionPointRevocationCheckerTests
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
/**
* Creates a new test instance with given parameters.
*
* @param checker Revocation checker instance.
* @param expiredCRLPolicy Policy instance for handling expired CRL data.
* @param certFiles File names of certificates to check.
* @param crlFile File name of CRL file to serve out.
* @param expected Expected result of check; null to indicate expected success.
*/
public CRLDistributionPointRevocationCheckerTests(
final CRLDistributionPointRevocationChecker checker,
final RevocationPolicy<X509CRL> expiredCRLPolicy,
final String[] certFiles,
final String crlFile,
final GeneralSecurityException expected) throws Exception {
super(certFiles, expected);
final File file = new File(System.getProperty("java.io.tmpdir"), "ca.crl");
if (file.exists()) {
file.delete();
}
final OutputStream out = new FileOutputStream(file);
IOUtils.copy(new ClassPathResource(crlFile).getInputStream(), out);
this.checker = checker;
this.checker.setExpiredCRLPolicy(expiredCRLPolicy);
this.webServer = new MockWebServer(8085, new FileSystemResource(file), "text/plain");
logger.debug("Web server listening on port 8085 serving file {}", crlFile);
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:31,代码来源:CRLDistributionPointRevocationCheckerTests.java
示例4: casSamlIdPMetadataResolver
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Bean
public MetadataResolver casSamlIdPMetadataResolver() {
try {
final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
final ResourceBackedMetadataResolver resolver = new ResourceBackedMetadataResolver(
ResourceHelper.of(new FileSystemResource(idp.getMetadata().getMetadataFile())));
resolver.setParserPool(this.openSamlConfigBean.getParserPool());
resolver.setFailFastInitialization(idp.getMetadata().isFailFast());
resolver.setRequireValidMetadata(idp.getMetadata().isRequireValidMetadata());
resolver.setId(idp.getEntityId());
resolver.initialize();
return resolver;
} catch (final Exception e) {
throw new BeanCreationException(e.getMessage(), e);
}
}
示例5: createGoogleAppsPrivateKey
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
/**
* Create the private key.
*
* @throws Exception if key creation ran into an error
*/
protected void createGoogleAppsPrivateKey() throws Exception {
if (!isValidConfiguration()) {
LOGGER.debug("Google Apps private key bean will not be created, because it's not configured");
return;
}
final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
if (this.privateKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else if (this.privateKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
} else {
bean.setLocation(new FileSystemResource(this.privateKeyLocation));
}
bean.setAlgorithm(this.keyAlgorithm);
LOGGER.debug("Loading Google Apps private key from [{}] with key algorithm [{}]",
bean.getLocation(), bean.getAlgorithm());
bean.afterPropertiesSet();
LOGGER.debug("Creating Google Apps private key instance via [{}]", this.privateKeyLocation);
this.privateKey = bean.getObject();
}
示例6: ableToUploadFileFromConsumer
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Test
public void ableToUploadFileFromConsumer() throws IOException {
String file1Content = "hello world";
String file2Content = "bonjour";
String username = "mike";
Map<String, Object> map = new HashMap<>();
map.put("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
map.put("someFile", new FileSystemResource(newFile(file2Content).getAbsolutePath()));
map.put("name", username);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
String result = RestTemplateBuilder.create().postForObject(
"cse://springmvc-tests/codeFirstSpringmvc/upload",
new HttpEntity<>(map, headers),
String.class);
assertThat(result, is(file1Content + file2Content + username));
}
示例7: ableToUploadFileWithoutAnnotation
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Test
public void ableToUploadFileWithoutAnnotation() throws IOException {
String file1Content = "hello world";
String file2Content = "bonjour";
String username = "mike";
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
map.add("file2", new FileSystemResource(newFile(file2Content).getAbsolutePath()));
map.add("name", username);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
String result = restTemplate.postForObject(
codeFirstUrl + "uploadWithoutAnnotation",
new HttpEntity<>(map, headers),
String.class);
assertThat(result, is(file1Content + file2Content + username));
}
示例8: setUp
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"file:src/main/webapp/WEB-INF/cas-management-servlet.xml",
"file:src/main/webapp/WEB-INF/managementConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例9: kerberosTicketValidator
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Bean
public KerberosTicketValidator kerberosTicketValidator() throws Exception {
if (kerberosTicketValidator == null && properties.isKerberosSpnegoSupportEnabled()) {
// Configure SunJaasKerberos (global)
final File krb5ConfigFile = properties.getKerberosConfigurationFile();
if (krb5ConfigFile != null) {
final GlobalSunJaasKerberosConfig krb5Config = new GlobalSunJaasKerberosConfig();
krb5Config.setKrbConfLocation(krb5ConfigFile.getAbsolutePath());
krb5Config.afterPropertiesSet();
}
// Create ticket validator to inject into KerberosServiceAuthenticationProvider
SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator();
ticketValidator.setServicePrincipal(properties.getKerberosSpnegoPrincipal());
ticketValidator.setKeyTabLocation(new FileSystemResource(properties.getKerberosSpnegoKeytabLocation()));
ticketValidator.afterPropertiesSet();
kerberosTicketValidator = ticketValidator;
}
return kerberosTicketValidator;
}
示例10: innofactorReader
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Bean
@StepScope
@Qualifier(STEP_NAME)
public FlatFileItemReader<InnofactorImportFileLine> innofactorReader(
@Value("#{jobParameters['inputFile']}") String inputFile) {
FlatFileItemReader<InnofactorImportFileLine> reader = new FlatFileItemReader<>();
reader.setEncoding(StandardCharsets.UTF_8.name());
reader.setLineMapper(innofactorImportLineMapper());
reader.setStrict(true);
reader.setResource(new FileSystemResource(inputFile));
reader.setLinesToSkip(0);
reader.setBufferedReaderFactory(bufferedReaderFactory);
return reader;
}
示例11: ableToUploadFile
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Test
public void ableToUploadFile() throws IOException {
String file1Content = "hello world";
String file2Content = "bonjour";
String username = "mike";
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
map.add("someFile", new FileSystemResource(newFile(file2Content).getAbsolutePath()));
map.add("name", username);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
String result = restTemplate.postForObject(
codeFirstUrl + "upload",
new HttpEntity<>(map, headers),
String.class);
assertThat(result, is(file1Content + file2Content + username));
}
示例12: blowsUpWhenFileNameDoesNotMatch
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Test
public void blowsUpWhenFileNameDoesNotMatch() throws IOException {
String file1Content = "hello world";
String file2Content = "bonjour";
MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file1", new FileSystemResource(newFile(file1Content).getAbsolutePath()));
map.add("unmatched name", new FileSystemResource(newFile(file2Content).getAbsolutePath()));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
try {
restTemplate.postForObject(
codeFirstUrl + "uploadWithoutAnnotation",
new HttpEntity<>(map, headers),
String.class);
expectFailing(UnknownHttpStatusCodeException.class);
} catch (RestClientException ignored) {
}
}
示例13: setUp
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"classpath:/webappContext.xml",
"file:src/main/webapp/WEB-INF/cas-servlet.xml",
"file:src/main/webapp/WEB-INF/deployerConfigContext.xml",
"file:src/main/webapp/WEB-INF/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return getClassLoader();
}
}));
applicationContext.refresh();
}
示例14: setUp
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Before
public void setUp() {
applicationContext = new XmlWebApplicationContext();
applicationContext.setConfigLocations(
"classpath:/cas-management-servlet.xml",
"classpath:/managementConfigContext.xml",
"classpath:/spring-configuration/*.xml");
applicationContext.setServletContext(new MockServletContext(new ResourceLoader() {
@Override
public Resource getResource(final String location) {
return new FileSystemResource("src/main/webapp" + location);
}
@Override
public ClassLoader getClassLoader() {
return WiringTests.class.getClassLoader();
}
}));
applicationContext.refresh();
}
示例15: createInstance
import org.springframework.core.io.FileSystemResource; //导入依赖的package包/类
@Override
public PublicKey createInstance() throws Exception {
try {
final PublicKeyFactoryBean factory = publicKeyFactoryBeanClass.newInstance();
if (this.location.startsWith("classpath:")) {
factory.setLocation(new ClassPathResource(StringUtils.removeStart(this.location, "classpath:")));
} else {
factory.setLocation(new FileSystemResource(this.location));
}
factory.setAlgorithm(this.algorithm);
factory.setSingleton(false);
return factory.getObject();
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
throw new RuntimeException(e);
}
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:18,代码来源:RegisteredServicePublicKeyImpl.java