List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:org.apache.james.container.spring.resource.AbstractJamesResourceLoader.java
/** * Return the {@link Resource} for the given url. If the resource can not be * found null get returned//w w w .j ava 2 s . c o m * * @see org.springframework.core.io.ResourceLoader#getResource(java.lang.String) */ public Resource getResource(String fileURL) { Resource r = null; if (fileURL.startsWith(FileSystem.CLASSPATH_PROTOCOL)) { String resourceName = fileURL.substring(FileSystem.CLASSPATH_PROTOCOL.length()); r = new ClassPathResource(resourceName); } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL)) { File file = null; if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_CONF)) { file = new File( getConfDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL_AND_CONF.length())); } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_VAR)) { file = new File( getVarDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL_AND_VAR.length())); } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_ABSOLUTE)) { file = new File( getAbsoluteDirectory() + fileURL.substring(FileSystem.FILE_PROTOCOL_ABSOLUTE.length())); } else { // move to the root folder of the spring deployment file = new File(getRootDirectory() + "/" + fileURL.substring(FileSystem.FILE_PROTOCOL.length())); } r = new FileSystemResource(file); } else { return null; } return r; }
From source file:org.cbio.portal.pipelines.foundation.MutationDataWriter.java
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { // retrieve list of foundation cases from execution context final List<CaseType> fmiCaseList = (List<CaseType>) executionContext.get("fmiCaseList"); String stagingFile = outputDirectory + "data_mutations_extended.txt"; PassThroughLineAggregator aggr = new PassThroughLineAggregator(); flatFileItemWriter.setLineAggregator(aggr); flatFileItemWriter.setHeaderCallback(new FlatFileHeaderCallback() { @Override//from ww w. ja v a2 s . c o m public void writeHeader(Writer writer) throws IOException { writer.write(getHeader(fmiCaseList)); } }); flatFileItemWriter.setResource(new FileSystemResource(stagingFile)); flatFileItemWriter.open(executionContext); }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReaderTest.java
/** * Test with zip file with nested directories, contains 4 text files with * 20 lines each.// ww w .java 2 s .c o m * * @throws Exception */ @Test public void testOneZipFileNestedDirs() throws Exception { LOG.debug("testOneZipFileNestedDirs"); ZipMultiResourceItemReader<String> mReader = new ZipMultiResourceItemReader<String>(); // setup multResourceReader mReader.setArchives(new Resource[] { new FileSystemResource(ZIP_INPUT_NESTED_DIRS) }); // 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) { count++; } } while (item != null); assertEquals(80, count); } catch (Exception e) { throw e; } finally { mReader.close(); } }
From source file:org.kurento.repository.test.util.HttpRepositoryTest.java
protected void uploadFileWithMultiparts(String uploadURL, File fileToUpload) { RestTemplate template = getRestTemplate(); MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); parts.add("file", new FileSystemResource(fileToUpload)); ResponseEntity<String> entity = postWithRetries(uploadURL, template, parts); assertEquals("Returned response: " + entity.getBody(), HttpStatus.OK, entity.getStatusCode()); }
From source file:demo.FleetLocationRandomizer.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)) { list.add(randomize(location));//from ww w . ja va 2 s . c o m } this.mapper.writeValue(new FileSystemResource("new_fleet.json").getOutputStream(), list); }
From source file:org.broadleafcommerce.admin.util.controllers.FileUploadController.java
private void checkDirectory(String basepath) { FileSystemResource dirResource = new FileSystemResource(basepath); if (!dirResource.exists()) { File f = new File(basepath); if (!f.mkdirs()) { throw new RuntimeException("Could not create directories " + f.getAbsolutePath()); }/*from w w w.j a v a 2s . co m*/ } }
From source file:com.flipkart.aesop.runtime.impl.admin.RuntimeConfigServiceImpl.java
/** * Interface method implementation. Returns null if the Resource is not found * @see com.flipkart.aesop.runtime.spi.admin.RuntimeConfigService#getRuntimeConfig(java.lang.String) *///from www.jav a 2 s . c om public Resource getRuntimeConfig(String runtimeName) { for (URI configFile : this.configURItoRuntimeName.keySet()) { for (ServerContainer runtime : this.configURItoRuntimeName.get(configFile)) { if (runtime.getComponentAdmin().getComponentName().equals(runtimeName)) { return new FileSystemResource(new File(configFile)); } } } return null; }
From source file:org.opennms.ng.services.polloutagesconfig.PollOutagesConfigFactory.java
/** * Load the config from the default config file and create the singleton * instance of this factory.//from w w w. ja v a 2s . c o m * * @throws java.io.IOException Thrown if the specified config file cannot be read * @throws org.exolab.castor.xml.MarshalException Thrown if the file does not conform to the schema. * @throws org.exolab.castor.xml.ValidationException Thrown if the contents do not match the required schema. * @throws java.io.IOException if any. * @throws org.exolab.castor.xml.MarshalException if any. * @throws org.exolab.castor.xml.ValidationException if any. */ public static synchronized void init() throws IOException, MarshalException, ValidationException { if (m_loaded) { // init already called - return // to reload, reload() will need to be called return; } m_singleton = new PollOutagesConfigFactory(new FileSystemResource( ConfigFileConstants.getFile(ConfigFileConstants.POLL_OUTAGES_CONFIG_FILE_NAME))); m_singleton.afterPropertiesSet(); m_loaded = true; }
From source file:org.jasig.cas.services.RegisteredServicePublicKeyImpl.java
@Override public PublicKey createInstance() throws Exception { try {/*from w w w . j ava 2 s . c o m*/ 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); } }
From source file:fr.acxio.tools.agia.tasks.FileOperationTaskletTest.java
@Test(expected = IllegalArgumentException.class) public void testExecuteCopyDestinationFileNotFound() throws Exception { FileOperationTasklet aTasklet = new FileOperationTasklet(); aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/notfound.csv")); aTasklet.setOperation(Operation.COPY); aTasklet.afterPropertiesSet();//from w w w . j a v a2 s . co m }