List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:com.ables.pix.utility.PictureOps.java
private void rotatePicture(Picture pic, double rotation) { ResourceLoader loader = new FileSystemResourceLoader(); Resource resource = loader.getResource(repositoryRoot + pic.getLocation()); BufferedImage image;/*from w ww. j a v a2s . c om*/ try { image = ImageIO.read(resource.getFile()); BufferedImage result = tilt(image, rotation); String fileName = pic.getFileName(); ImageIO.write(result, fileName.substring(fileName.indexOf('.' + 1)), new File(resource.getFile().toURI())); } catch (IOException io) { throw new RuntimeException("Failed to rotate image", io); } }
From source file:org.pentaho.pat.server.util.JdbcDriverFinder.java
public void afterPropertiesSet() throws Exception { Assert.notNull(jdbcDriverPath);// w w w. ja va 2 s . c o m Assert.notNull(resourceLoader); for (String currentPath : this.jdbcDriverPath) { final Resource res = resourceLoader.getResource(currentPath); if (res == null || !res.exists()) { continue; } final File currentFile = res.getFile(); if (!currentFile.isDirectory() || !currentFile.canRead()) { continue; } this.jdbcDriverDirectory.add(currentFile); if (preLoad) { registerDrivers(); } } if (this.jdbcDriverDirectory.size() == 0) { LOG.warn(Messages.getString("Util.JdbcDriverFinder.NoDriversInPath")); //$NON-NLS-1$ } }
From source file:com.wavemaker.commons.classloader.ThrowawayFileClassLoader.java
@Override protected URL findResource(String name) { URL ret = null;/* w w w . j ava 2 s.c o m*/ JarFile jarFile = null; try { for (Resource entry : this.classPath) { if (entry.getFilename().toLowerCase().endsWith(".jar")) { jarFile = new JarFile(entry.getFile()); ZipEntry ze = jarFile.getEntry(name); jarFile.close(); if (ze != null) { ret = new URL("jar:" + entry.getURL() + "!/" + name); break; } } else { Resource file = entry.createRelative(name); if (file.exists()) { ret = file.getURL(); break; } } } } catch (IOException e) { throw new WMRuntimeException(e); } return ret; }
From source file:org.jnap.core.assets.HandlebarsAssetsHandler.java
@Override public void handle() { final Handlebars handlebars = new Handlebars(); try {/*from www .j a v a 2s. c o m*/ Resource[] resources = this.resourceResolver.getResources(source); Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); BufferedWriter writer = new BufferedWriter( new FileWriterWithEncoding(destRes.getFile(), this.encoding, true)); writer.write("(function() {"); writer.write(IOUtils.LINE_SEPARATOR); writer.write("var template = Handlebars.template, "); writer.write("templates = Handlebars.templates = Handlebars.templates || {};"); writer.write(IOUtils.LINE_SEPARATOR); final Set<String> templateNames = new TreeSet<String>(); for (Resource resource : resources) { Template template = handlebars .compile(StringUtils.trimToEmpty(IOUtils.toString(resource.getInputStream()))); final String templateName = FilenameUtils.getBaseName(resource.getFilename()); templateNames.add(templateName); writer.write("templates[\"" + templateName + "\"] = "); writer.write("template("); writer.write(template.toJavaScript()); writer.write(");"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write(IOUtils.LINE_SEPARATOR); if (this.bindToBackboneView) { writer.write("$(function() {"); writer.write(IOUtils.LINE_SEPARATOR); for (String templateName : templateNames) { writer.write(format("if (window[\"{0}\"]) {0}.prototype.template " + "= templates[\"{0}\"];", templateName)); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("});"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("})();"); IOUtils.closeQuietly(writer); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.processpuzzle.application.configuration.domain.PropertyContext.java
@Override protected void setUpTransientComponents() { File resourceFile = null;/* w w w . j a va 2 s .c om*/ try { log.debug("Trying to load resource: " + configurationDescriptorUrl); Resource resource = loader.getResource(configurationDescriptorUrl); if (resource != null) resourceFile = resource.getFile(); else throw new IOException( "Configuration descriptor: " + configurationDescriptorUrl + " can't be load."); DefaultConfigurationBuilder configurationBuilder = new DefaultConfigurationBuilder(resourceFile); configuration = configurationBuilder.getConfiguration(true); configuration.setExpressionEngine(new DefaultExpressionEngine()); } catch (ConfigurationException e) { log.debug(e.getMessage()); throw new ConfigurationSetUpException(configurationDescriptorUrl, e); } catch (IOException e) { throw new UndefinedPropertyDescriptorException(configurationDescriptorUrl, e); } }
From source file:com.netflix.genie.web.configs.GenieApiAutoConfiguration.java
/** * Get the jobs dir as a Spring Resource. Will create if it doesn't exist. * * @param resourceLoader The resource loader to use * @param jobsProperties The jobs properties to use * @return The job dir as a resource/*ww w .j a v a2s .c o m*/ * @throws IOException on error reading or creating the directory */ @Bean @ConditionalOnMissingBean(name = "jobsDir", value = Resource.class) public Resource jobsDir(final ResourceLoader resourceLoader, final JobsProperties jobsProperties) throws IOException { final String jobsDirLocation = jobsProperties.getLocations().getJobs(); final Resource tmpJobsDirResource = resourceLoader.getResource(jobsDirLocation); if (tmpJobsDirResource.exists() && !tmpJobsDirResource.getFile().isDirectory()) { throw new IllegalStateException(jobsDirLocation + " exists but isn't a directory. Unable to continue"); } // We want the resource to end in a slash for use later in the generation of URL's final String slash = "/"; String localJobsDir = jobsDirLocation; if (!jobsDirLocation.endsWith(slash)) { localJobsDir = localJobsDir + slash; } final Resource jobsDirResource = resourceLoader.getResource(localJobsDir); if (!jobsDirResource.exists()) { final File file = jobsDirResource.getFile(); if (!file.mkdirs()) { throw new IllegalStateException( "Unable to create jobs directory " + jobsDirLocation + " and it doesn't exist."); } } return jobsDirResource; }
From source file:com.wavemaker.tools.project.LocalStudioFileSystem.java
public static Resource staticGetWaveMakerHome() { Resource ret = null; String env = System.getProperty(WMHOME_PROP_KEY, null); if (env != null && 0 != env.length()) { ret = new FileSystemResource(env); }/*from w w w. j a v a2 s . c o m*/ if (ret == null) { String pref = ConfigurationStore.getPreference(LocalStudioConfiguration.class, WMHOME_KEY, null); if (pref != null && 0 != pref.length()) { pref = pref.endsWith("/") ? pref : pref + "/"; ret = new FileSystemResource(pref); } } // we couldn't find a test value, a property, or a preference, so use // a default if (ret == null) { System.out.println("INFO: Using default WaveMaker Home folder"); ret = getDefaultWaveMakerHome(); } if (!ret.exists()) { try { ret.getFile().mkdir(); } catch (IOException ex) { throw new WMRuntimeException(ex); } } return ret; }
From source file:mvctest.web.TestController.java
@RequestMapping(value = "/appCtxGetResourceGetFile") public void appCtxGetResourceGetFile(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = getRequiredStringParameter(request, "path"); String output = "<html><head><title>Testing path [" + path + "]</title></head><body>"; Resource resource = this.resourceLoader.getResource(path); File file = resource.getFile(); output += "From ApplicationContext/ResourceLoader's getResource().getFile() for [" + path + "]: file exists: " + file.exists() + "; canonical path: " + file.getCanonicalPath(); output += "</body></html>"; response.getWriter().write(output);/*from ww w . ja v a 2 s . c om*/ }
From source file:org.esupportail.portlet.filemanager.services.ResourceUtils.java
public void afterPropertiesSet() throws Exception { try {//w w w. j av a 2 s . co m Resource iconsFolder = rl.getResource("img/icons"); assert iconsFolder.exists(); FileFilter fileFilter = new WildcardFileFilter("*.png"); List<File> files = Arrays.asList(iconsFolder.getFile().listFiles(fileFilter)); for (File icon : files) { String iconName = icon.getName(); icons.put(iconName.substring(0, iconName.length() - 4), "/esup-filemanager/img/icons/".concat(iconName)); } log.debug("mimetypes incons retrieved : " + icons.toString()); } catch (FileNotFoundException e) { log.error("FileNotFoundException getting icons ...", e); } }