类org.springframework.core.io.PathResource源码实例Demo

下面列出了怎么用org.springframework.core.io.PathResource的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: DataLink   文件: PropertiesUtil.java
/**
 * 获取properties文件内容
 *
 * @param propertiesPath :绝对路径
 * @return
 */
public static Properties getProperties(String propertiesPath) throws IOException {

    Properties resultProperties = propertiesMap.get(propertiesPath);

    if (resultProperties == null) {
        Resource resource = new PathResource(propertiesPath);
        try {
            resultProperties = PropertiesLoaderUtils.loadProperties(resource);
        } catch (FileNotFoundException e) {
            resultProperties = null;
        }

        if (resultProperties != null)
            propertiesMap.put(propertiesPath, resultProperties);
    }

    return resultProperties;
}
 
@Bean
@StepScope
public FlatFileItemReader<PatientRecord> reader(
    @Value("#{jobParameters['" + Constants.JOB_PARAM_FILE_NAME + "']}")String fileName) {
    return new FlatFileItemReaderBuilder<PatientRecord>()
        .name(Constants.ITEM_READER_NAME)
        .resource(
            new PathResource(
                Paths.get(applicationProperties.getBatch().getInputPath() +
                    File.separator + fileName)))
        .linesToSkip(1)
        .lineMapper(lineMapper())
        .build();
}
 
源代码3 项目: haven-platform   文件: ApplicationApi.java
@RequestMapping(value = "{cluster}/{appId}/initFile", method = GET, produces = APPLICATION_OCTET_STREAM_VALUE)
public ResponseEntity<Resource> getInitFile(@PathVariable("cluster") String cluster, @PathVariable("appId") String appId) {
    File initComposeFile = applicationService.getInitComposeFile(cluster, appId);
    log.info("fetching config file for application: {}, cluster: {}, path {}", appId, cluster, initComposeFile);
    if (!initComposeFile.exists()) {
        throw new NotFoundException("file not found " + initComposeFile);
    }
    HttpHeaders respHeaders = new HttpHeaders();
    respHeaders.set("Content-Disposition", "attachment; filename=" + initComposeFile.getName());
    respHeaders.setContentLength(initComposeFile.length());

    return new ResponseEntity<>(new PathResource(initComposeFile.toPath()), respHeaders, HttpStatus.OK);
}
 
 类方法
 同包方法