List of usage examples for org.springframework.core.io FileSystemResource FileSystemResource
public FileSystemResource(Path filePath)
From source file:com.jbrisbin.vpc.jobsched.SpringResourceConnector.java
public URLConnection getResourceConnection(String name) throws ResourceException { Resource res = null;//w w w .jav a2 s. com if (name.startsWith("classpath:")) { res = new ClassPathResource(name.substring(10)); } else if (name.startsWith("http")) { try { res = new UrlResource(name); } catch (MalformedURLException e) { log.error(e.getMessage(), e); } } else { res = new FileSystemResource(name); } try { return res.getURI().toURL().openConnection(); } catch (IOException e) { log.error(e.getMessage(), e); throw new ResourceException(e); } }
From source file:fi.csc.emrex.smp.PDFController.java
@RequestMapping(value = "/elmo", method = RequestMethod.GET) @ResponseBody/*from ww w . j a va 2 s .c o m*/ public FileSystemResource elmo(HttpServletResponse response, Model model, @CookieValue(value = "elmoSessionId") String sessionIdCookie) throws Exception { final String decodedXml = (String) context.getSession().getAttribute("elmoxmlstring"); new PdfGen().generatePdf(decodedXml, "/tmp/elmo.pdf"); response.setHeader("Content-disposition", "attachment;filename=elmo.pdf"); response.setContentType("application/pdf"); return new FileSystemResource("/tmp/elmo.pdf"); }
From source file:net.sourceforge.jabm.spring.BeanFactorySingleton.java
public static void initialiseFactory() { Properties systemProperties = SystemProperties.jabsConfiguration(); String configFile = systemProperties.getProperty(SystemProperties.PROPERTY_CONFIG); if (configFile == null) { throw new IllegalArgumentException("Must specify a configuration file by setting the system property " + SystemProperties.PROPERTY_BASE + "." + SystemProperties.PROPERTY_CONFIG); }/* w w w . j a va2 s .c o m*/ initialiseFactory(new FileSystemResource(configFile)); }
From source file:io.pivotal.poc.claimcheck.LocalFileClaimCheckStore.java
@Override public Resource find(String id) { return new FileSystemResource(new File(this.directory, id)); }
From source file:de.tudarmstadt.ukp.wikipedia.wikimachine.factory.SpringFactory.java
private static XmlBeanFactory getBeanFactory() { File outerContextFile = new File(OUTER_APPLICATION_CONTEXT); boolean outerContextFileProper = outerContextFile.exists() && outerContextFile.isFile() && outerContextFile.canRead(); Resource res = (outerContextFileProper) ? new FileSystemResource(outerContextFile) : new ClassPathResource(INNER_APPLICATION_CONTEXT); return new XmlBeanFactory(res); }
From source file:fr.acxio.tools.agia.io.ExpressionResourceFactory.java
@Override public synchronized Resource getResource(Map<? extends Object, ? extends Object> sParameters) throws ResourceCreationException { Resource aResult = null;/*from ww w.j a va 2 s . c om*/ if (expression != null) { try { updateContext(getVariableName(), sParameters, getEvaluationContext()); String aPath = getExpressionResolver().evaluate(expression, getEvaluationContext(), String.class); aResult = new FileSystemResource(aPath); } catch (Exception e) { throw new ResourceCreationException(e); } } return aResult; }
From source file:de.langmi.spring.batch.examples.readers.file.peekable.SimplePeekableItemReaderTest.java
/** * Test should read succesfully.//from ww w .ja va2 s. c o m * * @throws Exception */ @Test public void testSuccessfulPeekAhead() throws Exception { // init delegate delegateReader.setLineMapper(new PassThroughLineMapper()); delegateReader.setResource(new FileSystemResource(INPUT_FILE)); // init peekable SingleItemPeekableItemReader<String> peekable = new SingleItemPeekableItemReader<String>(); peekable.setDelegate(delegateReader); // open, provide "mock" ExecutionContext peekable.open(MetaDataInstanceFactory.createStepExecution().getExecutionContext()); // read try { int count = 0; String line; while ((line = peekable.read()) != null) { assertEquals(String.valueOf(count), line); // test for peek String lineAhead = peekable.peek(); if (count + 1 < EXPECTED_COUNT) { assertEquals(String.valueOf(count + 1), lineAhead); } else { assertNull(lineAhead); } count++; } assertEquals(EXPECTED_COUNT, count); } catch (Exception e) { throw e; } finally { peekable.close(); } }
From source file:org.apache.ftpserver.config.spring.SpringConfigTest.java
public void test() throws Throwable { XmlBeanFactory factory = new XmlBeanFactory( new FileSystemResource("src/test/resources/spring-config/config-spring-1.xml")); DefaultFtpServer server = (DefaultFtpServer) factory.getBean("server"); assertEquals(500, server.getConnectionConfig().getMaxLogins()); assertEquals(false, server.getConnectionConfig().isAnonymousLoginEnabled()); assertEquals(123, server.getConnectionConfig().getMaxAnonymousLogins()); assertEquals(124, server.getConnectionConfig().getMaxLoginFailures()); assertEquals(125, server.getConnectionConfig().getLoginFailureDelay()); Map<String, Listener> listeners = server.getServerContext().getListeners(); assertEquals(3, listeners.size());//from w ww.j ava 2 s. c o m Listener listener = listeners.get("listener0"); assertNotNull(listener); assertTrue(listener instanceof NioListener); assertEquals(2222, ((NioListener) listener).getPort()); assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener).getServerAddress())); assertEquals(100, ((NioListener) listener).getDataConnectionConfiguration().getIdleTime()); assertTrue(((NioListener) listener).getDataConnectionConfiguration().isActiveEnabled()); assertTrue(((NioListener) listener).getDataConnectionConfiguration().isImplicitSsl()); assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress .getByName(((NioListener) listener).getDataConnectionConfiguration().getActiveLocalAddress())); assertEquals("123-125", ((NioListener) listener).getDataConnectionConfiguration().getPassivePorts()); assertEquals(false, ((NioListener) listener).getDataConnectionConfiguration().isPassiveIpCheck()); RemoteIpFilter filter = (RemoteIpFilter) listener.getSessionFilter(); assertEquals(3, filter.size()); assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.0"), 16))); assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.4.0"), 16))); assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.4"), 32))); listener = listeners.get("listener1"); assertNotNull(listener); assertTrue(listener instanceof MyCustomListener); assertEquals(2223, listener.getPort()); listener = listeners.get("listener2"); assertNotNull(listener); assertTrue(listener instanceof MyCustomListener); assertEquals(2224, listener.getPort()); CommandFactory cf = server.getCommandFactory(); assertTrue(cf.getCommand("FOO") instanceof HELP); assertTrue(cf.getCommand("FOO2") instanceof STAT); List<String> languages = server.getServerContext().getMessageResource().getAvailableLanguages(); assertEquals(2, languages.size()); assertEquals("en", languages.get(0)); assertEquals("zh-tw", languages.get(1)); NativeFileSystemFactory fs = (NativeFileSystemFactory) server.getFileSystem(); assertTrue(fs.isCreateHome()); assertTrue(fs.isCaseInsensitive()); assertEquals(2, server.getFtplets().size()); assertEquals(123, ((TestFtplet) server.getFtplets().get("ftplet1")).getFoo()); assertEquals(223, ((TestFtplet) server.getFtplets().get("ftplet2")).getFoo()); }
From source file:org.brekka.stillingar.spring.snapshot.WatchedResourceMonitorTest.java
/** * Test method for {@link org.brekka.stillingar.spring.snapshot.WatchedResourceMonitor#hasChanged()}. *///from w w w.ja v a 2 s. co m @Test public void testHasChanged() throws Exception { File dir = new File(System.getProperty("java.io.tmpdir"), getClass().getSimpleName()); dir.mkdirs(); File file = new File(dir, "config.xml"); file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); watchedResourceMonitor.initialise(new FileSystemResource(file)); assertFalse(watchedResourceMonitor.hasChanged()); Thread.sleep(500); for (int i = 0; i < 3; i++) { fos.write("Test\n".getBytes()); fos.flush(); file.setLastModified(System.currentTimeMillis()); Thread.sleep(500); assertTrue(watchedResourceMonitor.hasChanged()); Thread.sleep(500); assertFalse(watchedResourceMonitor.hasChanged()); } fos.close(); file.delete(); dir.delete(); }
From source file:org.dspace.servicemanager.spring.ResourceFinder.java
private static Resource findResource(String path) { Resource r;/* ww w . j ava2 s . com*/ String envPath = getEnvironmentPath() + path; r = new FileSystemResource(envPath); if (!r.exists()) { // try the relative path next String relPath = getRelativePath() + path; r = new FileSystemResource(relPath); if (!r.exists()) { // now try the classloaders ClassLoader cl = ResourceFinder.class.getClassLoader(); r = new ClassPathResource(path, cl); if (!r.exists()) { // finally try the context classloader cl = Thread.currentThread().getContextClassLoader(); r = new ClassPathResource(path, cl); } } } return r; }