List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:org.alfresco.cacheserver.dropwizard.Application.java
/** * Creates a Spring property place holder configurer for use in a Spring context * from the given file path.//from w w w. j a v a2 s . c o m * * @param springPropsFileName * @return the Spring property place holder configurer * @throws IOException */ protected PropertyPlaceholderConfigurer loadSpringConfigurer(String yamlConfigFileLocation) throws IOException { if (StringUtils.isEmpty(yamlConfigFileLocation)) { throw new IllegalArgumentException("Config file location must not be empty"); } logger.debug("Loading properties from '" + yamlConfigFileLocation + "'"); PropertyPlaceholderConfigurer configurer = new PropertyPlaceholderConfigurer(); configurer.setLocation(new FileSystemResource(yamlConfigFileLocation)); configurer.setPropertiesPersister(new YamlPropertiesPersister()); return configurer; }
From source file:test.org.tradex.camel.TestCaseAppContextBuilder.java
/** * Creates a new application context using the file found at <code>ROOT_RESOURCE_DIR + clazz.getPackageName + fileName</code> * @param fileName The filename in the calculated directory * @param clazz The clazz we're launching the app context for * @return the app context//from w w w . j a va 2s. c o m */ public static GenericXmlApplicationContext buildFor(String fileName, Class<?> clazz) { if (clazz == null) throw new IllegalArgumentException("Passed class was null", new Throwable()); File springXml = new File( ROOT_RESOURCE_DIR + clazz.getPackage().getName().replace('.', '/') + "/" + fileName); if (!springXml.canRead()) { throw new RuntimeException("Failed to read Spring XML file at [" + springXml + "]", new Throwable()); } return service(new GenericXmlApplicationContext( new FileSystemResource[] { new FileSystemResource(springXml.getAbsoluteFile()) })); }
From source file:com.tdclighthouse.prototype.utils.Configuration.java
public Configuration(String systemPropertyName, String defaultPropertiesFileLocation) throws IOException { String propertyFilePath = System.getProperties().getProperty(systemPropertyName); Resource location = null;//from w ww . ja va2s . co m if (StringUtils.isNotBlank(propertyFilePath)) { location = new FileSystemResource(propertyFilePath); } else { location = new ClassPathResource(defaultPropertiesFileLocation); } properties = new Properties(); properties.load(location.getInputStream()); }
From source file:nu.yona.server.rest.StandardResourcesController.java
@RequestMapping(value = "/ssl/rootcert.cer", method = RequestMethod.GET, produces = { "application/pkix-cert" }) @ResponseBody//from w w w . jav a 2 s .c om public FileSystemResource getSslRootCert() { return new FileSystemResource(yonaProperties.getSecurity().getSslRootCertFile()); }
From source file:uk.ac.ebi.eva.pipeline.io.writers.VepInputFlatFileWriter.java
/** * @return must return a {@link FlatFileItemWriter} and not a {@link org.springframework.batch.item.ItemWriter} * {@see https://jira.spring.io/browse/BATCH-2097 * * TODO: The variant list should be compressed *//*from w w w. jav a2s .c om*/ public VepInputFlatFileWriter(File file) { super(); BeanWrapperFieldExtractor<VariantWrapper> fieldExtractor = new BeanWrapperFieldExtractor<>(); fieldExtractor.setNames(new String[] { "chr", "start", "end", "refAlt", "strand" }); DelimitedLineAggregator<VariantWrapper> delLineAgg = new DelimitedLineAggregator<>(); delLineAgg.setDelimiter("\t"); delLineAgg.setFieldExtractor(fieldExtractor); setResource(new FileSystemResource(file)); setAppendAllowed(false); setShouldDeleteIfExists(true); setLineAggregator(delLineAgg); }
From source file:com.inkubator.hrm.batch.PayTempOvertimeUploadReader.java
private void initializationCsvReader(String filePath) { //read a CSV file Resource resource = new FileSystemResource(filePath); //split by separated coma DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer(DelimitedLineTokenizer.DELIMITER_COMMA); lineTokenizer.setNames(new String[] { "Nik", "Overtime" }); //mapped to an object BeanWrapperFieldSetMapper<PayTempOvertimeFileModel> beanWrapperFieldSetMapper = new BeanWrapperFieldSetMapper<>(); beanWrapperFieldSetMapper.setTargetType(PayTempOvertimeFileModel.class); DefaultLineMapper<PayTempOvertimeFileModel> lineMapper = new DefaultLineMapper<>(); lineMapper.setLineTokenizer(lineTokenizer); lineMapper.setFieldSetMapper(beanWrapperFieldSetMapper); //initial flatFileItemReader csvFileReader = new FlatFileItemReader<>(); csvFileReader.setLineMapper(lineMapper); csvFileReader.setResource(resource); csvFileReader.setLinesToSkip(1);/* w ww . ja v a2 s . com*/ csvFileReader.open(new ExecutionContext()); }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java
/** * Test with one ZIP file containing one text file with 20 lines. * * @throws Exception /*w w w .j ava 2 s . c o m*/ */ @Test public void testOneZipFile() throws Exception { LOG.debug("testOneZipFile"); ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_SINGLE_FILE) }); // call general setup last generalMultiResourceReaderSetup(mReader); // open with mock context mReader.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { String item = null; int count = 0; do { item = mReader.read(); if (item != null) { assertEquals(String.valueOf(count), item); count++; } } while (item != null); assertEquals(20, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:demo.FleetLocationNarrower.java
@Override public void run(String... args) throws Exception { List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); for (Map<String, Object> location : loadJson(this.fleet)) { if (closeEnough(location)) { list.add(location);//w ww . j ava 2s .com } } this.mapper.writeValue(new FileSystemResource("new_fleet.json").getOutputStream(), list); }
From source file:com.github.ffremont.microservices.springboot.manager.nexus.NexusClientApiTest.java
@Test public void testGetBinaryFailed() throws IOException { String g = "gg", a = "aa", v = "1.0.0", c = "cc", p = "jar"; // init mock/*from ww w . jav a 2s . c o m*/ String path = Thread.currentThread().getContextClassLoader().getResource("empty.jar").getPath(); ResponseEntity responseEntity = new ResponseEntity(new FileSystemResource(path), HttpStatus.OK); //when(this.nexusRestTemplate.getForEntity(prop.getBaseurl()+"/service/local/artifact/maven/redirect?r=snapshots&g="+g+"&a="+a+"&v="+v+"&p="+p+"&c="+c, Resource.class)).thenReturn(responseEntity); Path r = nexus.getBinary(g, a, p, c, v); assertNull(r); }
From source file:util.ReadXml.java
public ReadXml(String xmlFile, String beanFile) { this.xmlFile = xmlFile; //BeanFactory resource = new FileSystemResource(beanFile); factory = new XmlBeanFactory(resource); //DOMparser factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try {/*from w ww. j a v a2 s .com*/ //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse(xmlFile); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } //get the root elememt docEle = dom.getDocumentElement(); }