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


Java FileSystemResource类代码示例

本文整理汇总了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();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:GoogleAccountsServiceResponseBuilder.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:ChainingMetadataResolverCacheLoader.java

示例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);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:SamlIdPConfiguration.java

示例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();
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:29,代码来源:GoogleAccountsServiceResponseBuilder.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:SpringMvcIntegrationTestBase.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:SpringMvcIntegrationTestBase.java

示例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();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:WiringTests.java

示例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;

}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:27,代码来源:KerberosTicketValidatorFactory.java

示例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;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:18,代码来源:InnofactorImportConfig.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:SpringMvcIntegrationTestBase.java

示例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) {
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:22,代码来源:SpringMvcIntegrationTestBase.java

示例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();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:22,代码来源:WiringTests.java

示例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();
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:21,代码来源:WiringTests.java

示例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


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