List of usage examples for org.springframework.core.io Resource exists
boolean exists();
From source file:org.springframework.boot.ImageBanner.java
public ImageBanner(Resource image) { Assert.notNull(image, "Image must not be null"); Assert.isTrue(image.exists(), "Image must exist"); this.image = image; }
From source file:org.springframework.boot.ResourceBanner.java
public ResourceBanner(Resource resource) { Assert.notNull(resource, "Resource must not be null"); Assert.isTrue(resource.exists(), "Resource must exist"); this.resource = resource; }
From source file:org.springframework.boot.SpringApplication.java
private Banner selectBanner(Environment environment) { String location = environment.getProperty("banner.location", "banner.txt"); ResourceLoader resourceLoader = this.resourceLoader != null ? this.resourceLoader : new DefaultResourceLoader(getClassLoader()); Resource resource = resourceLoader.getResource(location); if (resource.exists()) { return new ResourceBanner(resource); }/*w ww . j av a2 s. co m*/ if (this.banner != null) { return this.banner; } return DEFAULT_BANNER; }
From source file:org.springframework.boot.SpringApplicationBannerPrinter.java
private Banner getTextBanner(Environment environment) { String location = environment.getProperty(BANNER_LOCATION_PROPERTY, DEFAULT_BANNER_LOCATION); Resource resource = this.resourceLoader.getResource(location); if (resource.exists()) { return new ResourceBanner(resource); }/*from w ww. j av a 2 s . c om*/ return null; }
From source file:org.springframework.boot.SpringApplicationBannerPrinter.java
private Banner getImageBanner(Environment environment) { String location = environment.getProperty(BANNER_IMAGE_LOCATION_PROPERTY); if (StringUtils.hasLength(location)) { Resource resource = this.resourceLoader.getResource(location); return (resource.exists() ? new ImageBanner(resource) : null); }//from w w w. jav a 2 s. com for (String ext : IMAGE_EXTENSION) { Resource resource = this.resourceLoader.getResource("banner." + ext); if (resource.exists()) { return new ImageBanner(resource); } } return null; }
From source file:org.springframework.cloud.config.monitor.FileMonitorConfiguration.java
private Set<Path> getFileRepo() { if (this.scmRepositories != null) { String repositoryUri = null; Set<Path> paths = new LinkedHashSet<>(); try {//from www . j a v a2s .c o m for (AbstractScmEnvironmentRepository repository : scmRepositories) { repositoryUri = repository.getUri(); Resource resource = this.resourceLoader.getResource(repositoryUri); if (resource instanceof FileSystemResource) { paths.add(Paths.get(resource.getURI())); } } return paths; } catch (IOException e) { log.error("Cannot resolve URI for path: " + repositoryUri); } } if (this.nativeEnvironmentRepository != null) { Set<Path> paths = new LinkedHashSet<>(); for (String path : this.nativeEnvironmentRepository.getSearchLocations()) { Resource resource = this.resourceLoader.getResource(path); if (resource.exists()) { try { paths.add(Paths.get(resource.getURI())); } catch (Exception e) { log.error("Cannot resolve URI for path: " + path); } } } return paths; } return null; }
From source file:org.springframework.cloud.config.server.resource.GenericResourceRepository.java
@Override public synchronized Resource findOne(String application, String profile, String label, String path) { if (StringUtils.hasText(path)) { String[] locations = this.service.getLocations(application, profile, label).getLocations(); try {/*w w w. j a va 2 s . c o m*/ for (int i = locations.length; i-- > 0;) { String location = locations[i]; for (String local : getProfilePaths(profile, path)) { if (!isInvalidPath(local) && !isInvalidEncodedPath(local)) { Resource file = this.resourceLoader.getResource(location).createRelative(local); if (file.exists() && file.isReadable()) { return file; } } } } } catch (IOException e) { throw new NoSuchResourceException("Error : " + path + ". (" + e.getMessage() + ")"); } } throw new NoSuchResourceException("Not found: " + path); }
From source file:org.springframework.cloud.dataflow.server.config.DefaultEnvironmentPostProcessor.java
private static 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)); }// w w w . jav a 2 s . c o m } }
From source file:org.springframework.cloud.dataflow.server.single.security.OAuth2ServerResource.java
@Override protected void before() throws Throwable { originalOAuth2Port = System.getProperty(OAUTH2_PORT_PROPERTY); this.oauth2ServerPort = SocketUtils.findAvailableTcpPort(); LOGGER.info("Setting OAuth2 Server port to " + this.oauth2ServerPort); System.setProperty(OAUTH2_PORT_PROPERTY, String.valueOf(this.oauth2ServerPort)); final String configurationLocation = "classpath:/org/springframework/cloud/dataflow/server/single/security/support/oauth2TestServerConfig.yml"; final Resource resource = new PathMatchingResourcePatternResolver().getResource(configurationLocation); if (!resource.exists()) { throw new IllegalArgumentException(String .format("Resource 'configurationLocation' ('%s') does not exist.", configurationLocation)); }/*from ww w. j a v a 2 s. co m*/ this.application = new SpringApplicationBuilder(OAuth2TestServer.class).build().run( "--spring.cloud.common.security.enabled=false", "--spring.cloud.kubernetes.enabled=false", "--spring.config.additional-location=" + configurationLocation); }
From source file:org.springframework.data.hadoop.admin.web.TemplateController.java
@RequestMapping(value = "/templates/**", method = RequestMethod.GET) public String get(HttpServletRequest request, HttpServletResponse response, ModelMap model, @RequestParam(defaultValue = "0") int startFile, @RequestParam(defaultValue = "20") int pageSize, @ModelAttribute("date") Date date, Errors errors) throws Exception { list(model, startFile, pageSize);//from ww w . jav a 2 s.c o m String path = request.getPathInfo().substring("/templates/".length()); Resource file = templateService.getResource(path); if (file == null || !file.exists()) { errors.reject("file.download.missing", new Object[] { path }, "File download failed for missing file at path=" + HtmlUtils.htmlEscape(path)); return "templates"; } response.setContentType("application/octet-stream"); try { FileCopyUtils.copy(file.getInputStream(), response.getOutputStream()); } catch (IOException e) { errors.reject("file.download.failed", new Object[] { path }, "File download failed for path=" + HtmlUtils.htmlEscape(path)); logger.info("File download failed for path=" + path, e); return "templates"; } return null; }