Example usage for org.springframework.core.io FileSystemResource FileSystemResource

List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource

Introduction

In this page you can find the example usage for org.springframework.core.io FileSystemResource FileSystemResource.

Prototype

public FileSystemResource(Path filePath) 

Source Link

Document

Create a new FileSystemResource from a Path handle, performing all file system interactions via NIO.2 instead of File .

Usage

From source file:de.codecentric.batch.jobs.FlatFileToDbNoSkipJobConfiguration.java

@Bean
@StepScope/*from  w w  w  .j  a  va 2 s . c om*/
public FlatFileItemReader<Item> flatFileItemReader(@Value("#{jobParameters[pathToFile]}") String pathToFile) {
    FlatFileItemReader<Item> itemReader = new FlatFileItemReader<Item>();
    itemReader.setLineMapper(lineMapper());
    itemReader.setResource(new FileSystemResource("src/test/resources/" + pathToFile));
    return itemReader;
}

From source file:fr.treeptik.cloudunit.initializer.CloudUnitApplicationContext.java

@Bean
@Profile("production")
public static PropertySourcesPlaceholderConfigurer propertiesForProduction() throws Exception {
    PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
    File customFile = new File(System.getProperty("user.home") + "/.cloudunit/configuration.properties");
    Resource[] resources = null;/*  ww  w .  j  a va  2s  .c om*/
    if (customFile.exists()) {
        resources = new Resource[] { new ClassPathResource("application-production.properties"),
                new FileSystemResource(
                        new File(System.getProperty("user.home") + "/.cloudunit/configuration.properties")) };
    } else {
        logger.error(customFile.getAbsolutePath() + " is missing. It could generate configuration error");
        resources = new Resource[] { new ClassPathResource("application-production.properties"), };
    }
    pspc.setLocations(resources);
    pspc.setIgnoreUnresolvablePlaceholders(true);
    pspc.setLocalOverride(true);
    return pspc;
}

From source file:bibibi.controllers.CitationsController.java

@RequestMapping(value = "/export", method = RequestMethod.GET)
public HttpEntity<FileSystemResource> getFile() throws IOException {
    BibWriter bw = new BibWriter("export", this.citationRepository.findAll());
    bw.writeFile();/* w w w.  j  a  v a 2 s .  co m*/

    HttpHeaders header = new HttpHeaders();
    header.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + bw.getFile().getName());
    header.setContentLength(bw.getFile().length());

    return new HttpEntity<>(new FileSystemResource(bw.getFile()), header);
}

From source file:org.bigtester.ate.model.data.CaseDataProcessor.java

/**
 * {@inheritDoc}//from w w  w. j  av  a 2s .  co  m
 */
@Override
public void postProcessBeanFactory(@Nullable ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (beanFactory == null)
        throw new IllegalStateException("Spring Container initialization error");
    String[] homePageNames = beanFactory.getBeanNamesForType(Homepage.class, true, false);
    String[] lastPageNames = beanFactory.getBeanNamesForType(Lastpage.class, true, false);
    String[] regularPageNames = beanFactory.getBeanNamesForType(RegularPage.class, true, false);

    allPageNames = ArrayUtils.addAll(homePageNames, lastPageNames);
    allPageNames = ArrayUtils.addAll(allPageNames, regularPageNames);

    for (int i = 0; i < getAllPageNames().length; i++) {
        pageBeanDefs.add(beanFactory.getBeanDefinition(getAllPageNames()[i]));
    }

    for (int j = 0; j < pageBeanDefs.size(); j++) {
        if (null != pageBeanDefs.get(j).getPropertyValues()
                .getPropertyValue(XsdElementConstants.ATTR_BASEPAGEOBJECT_DATAFILE)) {
            caseDataFiles.add(new FileSystemResource((String) pageBeanDefs.get(j).getPropertyValues()
                    .getPropertyValue(XsdElementConstants.ATTR_BASEPAGEOBJECT_DATAFILE).getValue()));
        }
    }

    if (!caseDataFiles.isEmpty()) {
        dbInit = GlobalUtils.findDBInitializer(beanFactory);
        try {
            getDbInit().setInitXmlFiles(caseDataFiles);
        } catch (IOException e) {
            throw new BeanDefinitionValidationException("Page data file in page attribute can't be read!", e);
        }
        try {
            getDbInit().initialize(beanFactory);
        } catch (MalformedURLException | DatabaseUnitException | SQLException e) {
            throw new FatalBeanException("Case database creation error!", e);
        }
    }
}

From source file:com.solidmaps.webapp.service.ApostilamentosServiceImpl.java

private FileSystemResource generateZip(CompanyEntity companyEntity) {

    String fileName = FILE_PATH + "Apostilamento-" + companyEntity.getCnpj() + ".zip";
    FileOutputStream fos = null;/*from  w  w w .  j  a  v  a 2  s .c  o  m*/

    try {

        fos = new FileOutputStream(fileName);
        ZipOutputStream zos = new ZipOutputStream(fos);
        this.addToZip(zos, fileFederal);
        this.addToZip(zos, fileCivil);
        this.addToZip(zos, fileExercito);

        zos.closeEntry();
        zos.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FileSystemResource fileSystemResource = new FileSystemResource(fileName);

    return fileSystemResource;
}

From source file:com.goodhuddle.huddle.service.impl.ThemeServiceImpl.java

@Override
public Resource getThemeThumbnail(long themeId) {
    File thumbnail = getThemeFile(themeId, "thumbnail.jpg");
    if (thumbnail == null || !thumbnail.exists()) {
        thumbnail = getThemeFile(themeId, "thumbnail.png");
    }//from ww  w  .j ava2s.  c o  m
    return thumbnail != null && thumbnail.exists() ? new FileSystemResource(thumbnail)
            : new ClassPathResource("/static/images/no-theme-thumbnail.png");
}

From source file:org.apache.uima.ruta.resource.TreeWordList.java

/**
 * Constructs a TreeWordList from a file with path = filename
 * //from  ww w  . j  a  v  a2  s.co  m
 * @param pathname
 *          path of the file to create a TextWordList from
 */
public TreeWordList(String pathname, boolean dictRemoveWS) throws IOException {
    this(new FileSystemResource(pathname), dictRemoveWS);
}

From source file:org.dawnsci.marketplace.controllers.PageController.java

@RequestMapping(value = "/pages/**", method = RequestMethod.GET)
@ResponseBody//from   w  w  w  .  j  a  va2s  .c  o m
public ResponseEntity<FileSystemResource> picture(HttpServletRequest request) {

    String resource = ((String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE))
            .substring(1);
    Path path = fileService.getPageFile(resource).toPath();

    File file = path.toAbsolutePath().toFile();

    if (file.exists() && file.isFile()) {
        try {
            String detect = tika.detect(file);
            MediaType mediaType = MediaType.parseMediaType(detect);
            return ResponseEntity.ok().contentLength(file.length()).contentType(mediaType)
                    .body(new FileSystemResource(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        throw new ResourceNotFoundException();
    }
    return null;
}

From source file:de.langmi.spring.batch.examples.readers.file.gzip.GZipBufferedReaderFactoryTest.java

@Test
public void testDefaultWithGzipFile() throws Exception {
    // try to create 
    BufferedReader reader = gzbrf.create(new FileSystemResource(PATH_TO_COMPRESSED_TEST_FILE),
            Charset.defaultCharset().name());
    // creation successful?
    assertNotNull(reader);//from w  ww . java 2  s  . com
    // clean up, close the reader
    reader.close();
}