List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:de.langmi.spring.batch.examples.readers.file.archive.ArchiveMultiResourceItemReaderTest.java
/** * Test with one ZIP file containing two text files with 20 lines each. * One file is a .csv, the other a .txt, only the .csv should be used. * * @throws Exception /*from www .j a va2 s . c om*/ */ @Test public void testOneZipFileWithFilter() throws Exception { LOG.debug("testOneZipFileWithFilter"); ArchiveMultiResourceItemReader<String> mReader = new ArchiveMultiResourceItemReader<String>(); // setup multResourceReader // zip file contains 2 files, one with suffix .csv, which contains 20 lines mReader.setArchives(new Resource[] { new FileSystemResource("src/test/resources/input/file/archive/input-mixed-files.zip") }); // setup filter DefaultArchiveFileNameFilter fileNameFilter = new DefaultArchiveFileNameFilter(); fileNameFilter.setSuffixes(new String[] { ".csv" }); mReader.setFilenameFilter(fileNameFilter); // call general setup last, includes call to afterPropertiesSet generalMultiResourceReaderWithFilterSetup(mReader, fileNameFilter); // 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:com.springcryptoutils.core.keystore.DefaultKeyStoreFactoryBean.java
public void afterPropertiesSet() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, InitializationException { final String keyStoreLocation = System.getProperty("javax.net.ssl.keyStore"); if (keyStoreLocation == null || keyStoreLocation.trim().length() == 0) { throw new InitializationException( "no value was specified for the system property: javax.net.ssl.keyStore"); }//ww w . j av a2 s.c o m final String password = System.getProperty("javax.net.ssl.keyStorePassword"); final Resource location = new FileSystemResource(keyStoreLocation); keystore = KeyStore.getInstance("JKS"); keystore.load(location.getInputStream(), password.toCharArray()); }
From source file:nl.surfnet.coin.selfservice.service.impl.PersonAttributeLabelServiceJsonImpl.java
private void populate() throws IOException { Resource jsonResource;//from ww w .j av a 2s . c o m if (attributeJsonFile.startsWith("classpath:")) { jsonResource = new ClassPathResource(attributeJsonFile.substring("classpath:".length())); } else { jsonResource = new FileSystemResource(attributeJsonFile); } labelMap = parseStreamToAttributeLabelMap(IOUtils.toString(jsonResource.getInputStream())); }
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.storage.FileSystemStorage.java
public Resource getResource() { return new FileSystemResource(storage); }
From source file:fr.acxio.tools.agia.io.ChronoFileSystemResourceFactory.java
public Resource getResource() throws ResourceCreationException { FileSystemResource aFileSystemResource = null; try {// w ww . jav a 2 s.c o m DateTimeFormatter aFormatter = DateTimeFormat.forPattern(dateFormat); StringBuilder aFilename = new StringBuilder(); aFilename.append(prefix).append(aFormatter.print(new Instant())).append(suffix); aFileSystemResource = new FileSystemResource(aFilename.toString()); } catch (Exception e) { throw new ResourceCreationException(e); } return aFileSystemResource; }
From source file:fi.helsinki.moodi.config.OodiConfig.java
private KeyStore oodiKeyStore(String keystoreLocation, char[] keystorePassword) throws Exception { KeyStore keyStore = KeyStore.getInstance("PKCS12"); FileSystemResource keystoreFile = new FileSystemResource(new File(keystoreLocation)); keyStore.load(keystoreFile.getInputStream(), keystorePassword); return keyStore; }
From source file:org.opennms.tools.ThresholdEventTest.java
/** * Set up the test.//from w w w.j av a2s .c om * * @throws Exception the exception */ @Before public void setUp() throws Exception { MockLogAppender.setupLogging(); graphDao = new PropertiesGraphDao(); File graphTemplatesFile = new File("src/test/resources/opennms-home/etc/snmp-graph.properties"); graphDao.loadProperties("performance", new FileSystemResource(graphTemplatesFile)); Assert.assertFalse(graphDao.getAllPrefabGraphs().isEmpty()); }
From source file:fr.acxio.tools.agia.tasks.FileCopyTaskletTest.java
@Test public void testExecute() throws Exception { FileCopyTasklet aTasklet = new FileCopyTasklet(); aTasklet.setOrigin(new FileSystemResource("src/test/resources/testFiles/input.csv")); aTasklet.setDestination(new FileSystemResource("target/input-copy.csv")); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(1)).incrementReadCount(); verify(aStepContribution, times(1)).incrementWriteCount(1); }
From source file:org.broadleafcommerce.admin.util.controllers.FileUploadController.java
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException { // cast the bean FileUploadBean bean = (FileUploadBean) command; // let's see if there's content there MultipartFile file = bean.getFile(); if (file == null) { // hmm, that's strange, the user did not upload anything }/*from ww w. ja v a2 s . co m*/ try { String basepath = request.getPathTranslated().substring(0, request.getPathTranslated().indexOf(File.separator + "upload")); String absoluteFilename = basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename(); FileSystemResource fileResource = new FileSystemResource(absoluteFilename); checkDirectory(basepath + File.separator + bean.getDirectory()); backupExistingFile(fileResource, basepath + bean.getDirectory()); FileOutputStream fout = new FileOutputStream(new FileSystemResource( basepath + File.separator + bean.getDirectory() + File.separator + file.getOriginalFilename()) .getFile()); BufferedOutputStream bout = new BufferedOutputStream(fout); BufferedInputStream bin = new BufferedInputStream(file.getInputStream()); int x; while ((x = bin.read()) != -1) { bout.write(x); } bout.flush(); bout.close(); bin.close(); return super.onSubmit(request, response, command, errors); } catch (Exception e) { //Exception occured; e.printStackTrace(); throw new RuntimeException(e); // return null; } }
From source file:org.intalio.tempo.security.ws.BaseWS.java
protected void initStatics() { if (_initialized) return;//from w w w . j a va2s.c o m try { synchronized (BaseWS.class) { if (_initialized) return; LOG.debug("Initializing configuration."); String configDir = System.getProperty(Constants.CONFIG_DIR_PROPERTY); if (configDir == null) { throw new RuntimeException( "System property " + Constants.CONFIG_DIR_PROPERTY + " not defined."); } _configDir = new File(configDir); if (!_configDir.exists()) { throw new RuntimeException( "Configuration directory " + _configDir.getAbsolutePath() + " doesn't exist."); } Thread thread = Thread.currentThread(); ClassLoader oldClassLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getClass().getClassLoader()); FileSystemResource config = new FileSystemResource(new File(_configDir, "securityConfig.xml")); XmlBeanFactory factory = new XmlBeanFactory(config); PropertyPlaceholderConfigurer propsCfg = new PropertyPlaceholderConfigurer(); propsCfg.setSearchSystemEnvironment(true); propsCfg.postProcessBeanFactory(factory); _securityProvider = (SecurityProvider) factory.getBean("securityProvider"); _tokenService = (org.intalio.tempo.security.token.TokenService) factory.getBean("tokenService"); _initialized = true; } finally { thread.setContextClassLoader(oldClassLoader); } } } catch (RuntimeException except) { LOG.error("Error during initialization of security service", except); throw except; } }