List of usage examples for org.springframework.core.io Resource exists
boolean exists();
From source file:org.obiba.onyx.engine.variable.export.OnyxDataExportReader.java
@SuppressWarnings("unchecked") public List<OnyxDataExportDestination> read() throws IOException { List<OnyxDataExportDestination> onyxDestinations = new ArrayList<OnyxDataExportDestination>(); for (int i = 0; i < this.resources.length; i++) { Resource resource = this.resources[i]; if (resource.exists()) { onyxDestinations/* w w w. j a va 2 s. co m*/ .addAll((List<OnyxDataExportDestination>) xstream.fromXML(resource.getInputStream())); } } return onyxDestinations; }
From source file:com.example.journal.env.JournalEnvironmentPostProcessor.java
private void contributeDefaults(Map<String, Object> defaults, Resource resource) { if (resource.exists()) { YamlPropertiesFactoryBean yamlPropertiesFactoryBean = new YamlPropertiesFactoryBean(); yamlPropertiesFactoryBean.setResources(resource); yamlPropertiesFactoryBean.afterPropertiesSet(); Properties p = yamlPropertiesFactoryBean.getObject(); for (Object k : p.keySet()) { String key = k.toString(); defaults.put(key, p.get(key)); }//from ww w . ja va2 s .c om } }
From source file:ch.sbb.releasetrain.jsfbootadapter.FileDownloadUtil.java
@RequestMapping(value = "/static/**", method = RequestMethod.GET) public void getFile(HttpServletResponse response, HttpServletRequest request) { try {/*w w w.j a v a 2 s . c o m*/ String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); PathMatchingResourcePatternResolver res = new PathMatchingResourcePatternResolver(); Resource template = res.getResource(path); if (!template.exists()) { log.info("file n/a... " + path); return; } org.apache.commons.io.IOUtils.copy(template.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException ex) { log.info("Error writing file to output stream", ex); } }
From source file:com.hp.application.automation.tools.octane.tests.CopyResourceSCM.java
@Override public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { if (workspace.exists()) { listener.getLogger().println("Deleting existing workspace " + workspace.getRemote()); workspace.deleteRecursive();// w w w .j a v a 2 s .co m } Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:" + path + "/**"); for (Resource resource : resources) { if (resource.exists() && resource.isReadable()) { String urlString = resource.getURL().toExternalForm(); String targetName = urlString.substring(urlString.indexOf(path) + path.length()); byte[] fileContent = IOUtils.toByteArray(resource.getInputStream()); FileUtils.writeByteArrayToFile(new File(new File(workspace.getRemote(), targetPath), targetName), fileContent); } } return true; }
From source file:org.codehaus.griffon.plugins.XmlPluginDescriptorReader.java
public GriffonPluginInfo readPluginInfo(Resource pluginDescriptor) { try {/* w w w . j a v a 2 s. c o m*/ Resource pluginXml = pluginDescriptor.createRelative("plugin.xml"); if (pluginXml.exists()) { return new PluginInfo(pluginXml, pluginSettings); } } catch (IOException e) { // ignore } return null; }
From source file:ImplementacionDaoTestServices.java
@BeforeClass public void initDataBase() { String fileName = "sql/script.sql"; Resource resource = applicationContext.getResource(fileName); if (resource.exists()) { executeSqlScript(fileName, false); } else {// w w w. j a v a2s .c o m log.debug("No existe el archivo: {}" + resource); } }
From source file:nl.flotsam.calendar.core.memory.InMemoryComoundCalendarTest.java
@Test public void shouldParseNingCalendarCorrectly() throws IOException, ValidationException { Resource resource = new ClassPathResource("/ning.ical"); assertTrue(resource.exists()); URI uri = resource.getURI();//from w w w . j a v a2s . c o m InMemoryCompoundCalendarRepository repository = new InMemoryCompoundCalendarRepository(urlFetchService); Calendar calendar = repository.putCalendar("test", Arrays.asList(uri)); calendar = repository.getCalendar("test"); assertThat(calendar, is(not(nullValue()))); }
From source file:org.trustedanalytics.servicebroker.gearpump.service.file.ResourceManagerService.java
public boolean checkIfExists(String filePath) { Resource resource = getResourceForPath(filePath); return resource != null && resource.exists(); }
From source file:com.haulmont.cuba.core.sys.ResourcesImpl.java
@Override @Nullable//w ww. ja va 2s .c o m public InputStream getResourceAsStream(String location) { try { Resource resource = getResource(location); if (resource.exists()) return resource.getInputStream(); else return null; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.codecentric.boot.admin.controller.LogfileController.java
@RequestMapping("/logfile") @ResponseBody/*from w w w . j av a 2 s . c om*/ public String getLogfile(HttpServletResponse response) { String path = env.getProperty("logging.file"); if (path == null) { LOGGER.error("Logfile download failed for missing property 'logging.file'"); return "Logfile download failed for missing property 'logging.file'"; } Resource file = new FileSystemResource(path); if (!file.exists()) { LOGGER.error("Logfile download failed for missing file at path=" + path); return "Logfile download failed for missing file at path=" + path; } response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); try { FileCopyUtils.copy(file.getInputStream(), response.getOutputStream()); } catch (IOException e) { LOGGER.error("Logfile download failed for path=" + path); return "Logfile download failed for path=" + path; } return null; }