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.FlatFileJobConfiguration.java

@Bean
public ItemWriter<String> writer() {
    FlatFileItemWriter<String> writer = new FlatFileItemWriter<String>();
    writer.setResource(new FileSystemResource(new File("target/out-javaconfig.txt")));
    writer.setLineAggregator(new PassThroughLineAggregator<String>());
    return writer;
}

From source file:de.langmi.spring.batch.examples.readers.file.csv.CsvFlatFileItemReaderTest.java

/**
 * Test should read succesfully./*  w w w .j a v a  2s.  c  o  m*/
 *
 * @throws Exception 
 */
@Test
public void testSuccessfulReading() throws Exception {
    // init linetokenizer
    DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer();
    lineTokenizer.setNames(new String[] { "id", "value" });
    // init linemapper
    DefaultLineMapper<FieldSet> lineMapper = new DefaultLineMapper<FieldSet>();
    lineMapper.setLineTokenizer(lineTokenizer);
    lineMapper.setFieldSetMapper(new PassThroughFieldSetMapper());
    // init reader
    reader.setLineMapper(lineMapper);
    reader.setResource(new FileSystemResource(INPUT_FILE));
    // open, provide "mock" ExecutionContext
    reader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext());
    // read
    try {
        int count = 0;
        FieldSet line;
        while ((line = reader.read()) != null) {
            // really test for the fieldSet names and values
            assertEquals("id", line.getNames()[0]);
            assertEquals(String.valueOf(count), line.getValues()[0]);
            assertEquals("value", line.getNames()[1]);
            // csv contains entry like '0,foo0'
            assertEquals("foo" + String.valueOf(count), line.getValues()[1]);
            count++;
        }
        assertEquals(EXPECTED_COUNT, count);
    } catch (Exception e) {
        throw e;
    } finally {
        reader.close();
    }
}

From source file:com.glaf.activiti.util.ProcessUtils.java

public static byte[] getImage(String processDefinitionId) {
    byte[] bytes = null;
    ProcessDefinition processDefinition = cache.get(processDefinitionId);
    if (processDefinition == null) {
        ActivitiProcessQueryService activitiProcessQueryService = ContextFactory
                .getBean("activitiProcessQueryService");
        processDefinition = activitiProcessQueryService.getProcessDefinition(processDefinitionId);
    }//from w  w w . ja va  2s.c o m

    if (processDefinition != null) {
        String resourceName = processDefinition.getDiagramResourceName();
        if (resourceName != null) {
            String filename = ApplicationContext.getAppPath() + "/deploy/bpmn/"
                    + getImagePath(processDefinition);
            FileSystemResource fs = new FileSystemResource(filename);
            if (!fs.exists()) {
                try {
                    ActivitiDeployQueryService activitiDeployQueryService = ContextFactory
                            .getBean("activitiDeployQueryService");
                    InputStream inputStream = activitiDeployQueryService
                            .getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
                    logger.debug("save:" + filename);
                    FileUtils.save(filename, inputStream);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
            return FileUtils.getBytes(fs.getFile());
        }
    }

    return bytes;
}

From source file:com.textocat.textokit.resource.SpringResourceLocator.java

@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
    if (!super.initialize(aSpecifier, aAdditionalParams))
        return false;
    ////from   w  ww . ja  v  a 2  s  . c  o  m
    resourceMeta = resourceLoader.getResource(resourceLocation);
    if (resourceMeta == null) {
        throw new IllegalStateException(format("Can't wrap path %s into Resource", resourceLocation));
    }
    if (!resourceMeta.exists()) {
        // try to resolve against UIMA datapath
        try {
            File resourceFile = resourceMeta.getFile();
            resourceFile = UimaResourceUtils.resolveFile(resourceFile.getPath(), getResourceManager());
            resourceMeta = new FileSystemResource(resourceFile);
        } catch (Exception e) {
            throw new ResourceInitializationException(e);
        }
    }
    return true;
}

From source file:org.intalio.tempo.web.SysPropApplicationContextLoader.java

public void loadAppContext(String appContextFile, boolean loadDefinitionOnStartup) {
    if (appContextFile == null) {
        throw new IllegalArgumentException("Argument 'contextFile' is null");
    }//from w  ww  . j  a  v  a 2s. c  o m
    _appContextFile = SystemPropertyUtils.resolvePlaceholders(appContextFile);
    if (loadDefinitionOnStartup) {
        _beanFactory = new ClassPathXmlApplicationContext(_appContextFile);
    } else {
        if (_appContextFile.startsWith(FILE_PREFIX)) {
            _appContextFile = _appContextFile.substring(FILE_PREFIX.length());
        }
        Resource configResource = new FileSystemResource(_appContextFile);
        _beanFactory = new XmlBeanFactory(configResource);
    }
}

From source file:com.ar.dev.tierra.api.controller.FiscalController.java

@RequestMapping(value = "/factura_b", method = RequestMethod.POST)
@ResponseBody/*from   ww  w  .j a  va  2  s.  c  om*/
public FileSystemResource getFactura_b(@PathParam("factura") int factura, @PathParam("cliente") int cliente)
        throws IOException, InterruptedException {
    List<DetalleFactura> detalles = facadeService.getDetalleFacturaDAO().facturaDetalle(factura);
    Cliente c = facadeService.getClienteDAO().searchById(cliente);
    facadeService.getFiscalDAO().factura_a(detalles, c);
    return new FileSystemResource("command/factura_b.200");
}

From source file:com.smart.aqimonitor.client.AqiSettingDialog.java

public void init() {
    String workDir = System.getProperty("user.dir");
    File configFile = new File(workDir + File.separator + "config.properties");
    propertiesResource = new FileSystemResource(configFile);
    try {// w  w  w  . ja va2  s.  c o m
        props = PropertiesLoaderUtils.loadProperties(propertiesResource);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (props != null) {
        tfRetryTimes.setText(props.getProperty("query.retryTimes"));
        tfRetryGap.setText(props.getProperty("query.retryGap"));
        File file = new File(props.getProperty("result.path"));
        tfExportPath.setText(file.getAbsolutePath());
        tfExportPath.setCaretPosition(0);
    }
}

From source file:de.ingrid.iplug.dsc.index.ScriptedWmsDocumentProducerTest.java

public void testScriptedDatabaseDocumentProducer() throws Exception {

    PlugDescription pd = new PlugDescription();
    pd.put("WebmapXmlConfigFile", "src/test/resources/ingrid_webmap_client_config.xml");

    PlugDescriptionConfiguredWmsRecordSetProducer p = new PlugDescriptionConfiguredWmsRecordSetProducer();
    p.setStatusProvider(statusProvider);
    p.setIdTag("//capabilitiesUrl");
    p.configure(pd);/*from w ww.ja  va2 s  . com*/

    ScriptedWmsDocumentMapper m = new ScriptedWmsDocumentMapper();
    m.setMappingScript(new FileSystemResource("src/main/resources/mapping/wms_to_lucene.js"));
    m.setCompile(false);
    ScriptedIdfDocumentMapper mapper = new ScriptedIdfDocumentMapper();
    mapper.setMappingScript(new FileSystemResource("src/main/resources/mapping/wms_to_idf.js"));
    mapper.setCompile(false);

    List<IRecordMapper> mList = new ArrayList<IRecordMapper>();
    mList.add(m);
    mList.add(mapper);
    DscWmsDocumentProducer dp = new DscWmsDocumentProducer();
    dp.setRecordSetProducer(p);
    dp.setRecordMapperList(mList);
    //TODO define proper directory
    if (dp.hasNext()) {
        while (dp.hasNext()) {
            ElasticDocument doc = dp.next();
            // NOTICE: may be null (e.g. if service not reachable) !
            if (doc == null) {
                continue;
            }
            //writer.addDocument(doc);
        }
    } else {
        fail("No document produced");
    }

}

From source file:org.cloudfoundry.reconfiguration.util.StandardCloudUtilsTest.java

@Test
public void isUsingCloudServices() throws IOException {
    when(this.applicationContext.getResources("classpath*:/META-INF/cloud/cloud-services"))
            .thenReturn(new Resource[] { new FileSystemResource("src/test/resources/cloud-services") });
    when(this.applicationContext.getBeanNamesForType(UnusedCloudService.class, true, false))
            .thenReturn(new String[0]);
    when(this.applicationContext.getBeanNamesForType(UsedCloudService.class, true, false))
            .thenReturn(new String[] { "used-cloud-service-bean-name" });

    assertTrue(this.cloudUtils.isUsingCloudServices(this.applicationContext));
}

From source file:com.sharksharding.resources.register.bean.RegisterDataSource.java

/**
 * bean/*w  w w . ja v  a2  s  .  c  o m*/
 * 
 * @author gaoxianglong
 * 
 * @param nodePathValue
 *            zookeepervalue
 * 
 * @param resourceType
 *            
 * 
 * @return void
 */
public static void register(String nodePathValue, String resourceType) {
    if (null == aContext)
        return;
    final String tmpdir = TmpManager.createTmp();
    logger.debug("tmpdir-->" + tmpdir);
    try (BufferedWriter out = new BufferedWriter(new FileWriter(tmpdir))) {
        if (null != nodePathValue) {
            out.write(nodePathValue);
            out.flush();
            FileSystemResource resource = new FileSystemResource(tmpdir);
            ConfigurableApplicationContext cfgContext = (ConfigurableApplicationContext) aContext;
            DefaultListableBeanFactory beanfactory = (DefaultListableBeanFactory) cfgContext.getBeanFactory();
            /*
             * ?????ioc?,???bean,
             * loadBeanDefinitions()
             */
            new XmlBeanDefinitionReader(beanfactory).loadBeanDefinitions(resource);
            final String defaultBeanName = "jdbcTemplate";
            String[] beanNames = beanfactory.getBeanDefinitionNames();
            for (String beanName : beanNames) {
                /* ??beanNamejdbcTemplateJdbcTemplate */
                if (defaultBeanName.equals(beanName)) {
                    GetJdbcTemplate.setJdbcTemplate((JdbcTemplate) beanfactory.getBean(defaultBeanName));
                } else {
                    /* bean */
                    beanfactory.getBean(beanName);
                }
            }
        }
    } catch (Exception e) {
        throw new RegisterBeanException(e.toString());
    } finally {
        TmpManager.deleteTmp(tmpdir);
    }
}