List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:net.urosk.mifss.core.lib.db.ContentMetaDataSQLs.java
public String getCreateStorageTableDDL(DB_VENDOR vendor, String mainTable) throws IOException { Resource res = AppContext.getApplicationContext() .getResource("classpath:database/" + vendor.toString().toLowerCase() + "-ddl.sql"); String ddl = FileUtils.readFileToString(res.getFile()); ddl = ddl.replace(TABLE_NAME_MARK, mainTable); return ddl;/*w ww .j a v a 2 s .c o m*/ }
From source file:net.urosk.mifss.core.lib.db.ContentMetaDataSQLs.java
public String getDropStorageTableDDL(DB_VENDOR vendor, String mainTable) throws IOException { Resource res = AppContext.getApplicationContext() .getResource("classpath:database/" + vendor.toString().toLowerCase() + "-drop.sql"); String ddl = FileUtils.readFileToString(res.getFile()); ddl = ddl.replace(TABLE_NAME_MARK, mainTable); return ddl;//from w ww . j ava2 s . c om }
From source file:org.activiti.dmn.spring.autodeployment.AbstractAutoDeploymentStrategy.java
/** * Determines the name to be used for the provided resource. * /*from w w w . j a v a 2 s . c om*/ * @param resource * the resource to get the name for * @return the name of the resource */ protected String determineResourceName(final Resource resource) { String resourceName = null; if (resource instanceof ContextResource) { resourceName = ((ContextResource) resource).getPathWithinContext(); } else if (resource instanceof ByteArrayResource) { resourceName = resource.getDescription(); } else { try { resourceName = resource.getFile().getAbsolutePath(); } catch (IOException e) { resourceName = resource.getFilename(); } } return resourceName; }
From source file:org.activiti.rest.osgi.OsgiClassPathStore.java
/** * The only change is to resolver instantiation *//*from w ww .j a va 2s. c o m*/ @Override public void init() { // wrap the application context resource resolver with our own this.resolver = new OsgiClassPathStoreResourceResolver(applicationContext); // check if there are any resources that live under this path // this is valid for read-only classpaths (class files + JAR file contents) try { Resource[] resources = resolver.getResources("classpath*:" + classPath + "/**/*"); if (resources.length != 0) { exists = true; } else { resources = resolver.getResources("classpath*:" + classPath + "/*"); if (resources.length != 0) { exists = true; } } // NOTE: Locate root of web script store // NOTE: Following awkward approach is used to mirror lookup of web scripts within store. This // ensures root paths match. try { // Process each root resource - there may be several as the classpath* could match // multiple location that each contain the configured path. Resource rootResource = null; resources = applicationContext.getResources("classpath*:" + classPath + "*"); List<String> storeDirList = new ArrayList<String>(resources.length); for (Resource resource : resources) { String externalForm = resource.getURL().toExternalForm(); if (externalForm.endsWith(classPath) || externalForm.endsWith(classPath + "/")) { // we've found the right resource, let's now bind using string constructor // so that Spring 3 will correctly create relative paths String directoryPath = resource.getFile().getAbsolutePath(); if (resource.getFile().isDirectory() && !directoryPath.endsWith("/")) { directoryPath += "/"; } if (new FileSystemResource(directoryPath).exists()) { // retrieve file system directory storeDirList.add(resource.getFile().toURI().toURL().toExternalForm()); } } } this.storeDirs = storeDirList.toArray(new String[storeDirList.size()]); } catch (IOException ioErr) { // unable to resolve a storeDir - this is expected for certain protocols such as "vfszip" // it is not critical and those protocols don't require it during path resolution later if (logger.isDebugEnabled()) logger.debug("Unable to resolve storeDir for base path " + classPath); } } catch (IOException ioe) { throw new WebScriptException("Failed to initialise Web Script Store classpath: " + classPath, ioe); } if (!exists && mustExist) { throw new WebScriptException( "Web Script Store classpath:" + classPath + " must exist; it was not found"); } }
From source file:org.apache.camel.component.exec.ExecTestUtils.java
/** * Where on the file system is located the <code>classpathResource</code>? * /*from www. java2s .c o m*/ * @param classpathResource a resource in the classpath * @return null if the resource does not exist in the classpath. If the file * is not null the resource is guaranteed to exist on the file * system */ public static File getClasspathResourceFileOrNull(String classpathResource) { if (classpathResource == null) { return null; } try { Resource resource = new ClassPathResource(classpathResource); File resourceFile = resource.getFile(); return resourceFile; } catch (IOException ioe) { LOG.warn("The resource " + classpathResource + " does not exist!", ioe); return null; } }
From source file:org.apache.servicecomb.foundation.common.utils.Log4jUtils.java
private static void outputFile(List<Resource> resList, Properties properties) throws IOException { //??class???outputFile??log??? //must create org.slf4j.impl.Log4jLoggerAdapter by LoggerExtFactory //in order to redefine Log4jLoggerAdapter before other class load Log4jLoggerAdapter Logger log = LoggerFactory.getLogger(Log4jUtils.class); String content = genFileContext(resList, properties); //????,??//from w w w. j a va 2 s. c o m //log.info("Merged log4j:\n{}", content); Resource res = resList.get(resList.size() - 1); // ?res.getFilejar??getFile File file = new File(res.getURL().getPath()); if (!file.getParentFile().canWrite()) { log.error("Can not output {},because can not write to directory of file {}", MERGED_FILE, res.getURL().getPath()); return; } File mergedfile = new File(res.getFile().getParentFile(), MERGED_FILE); FileUtils.writeStringToFile(mergedfile, content); log.info("Write merged log4j config file to {}", mergedfile.getAbsolutePath()); }
From source file:org.betaconceptframework.astroboa.test.AstroboaTestContext.java
private void deleteResource(String resourceRelativePath) throws IOException { Resource versionDirectory = new ClassPathResource(resourceRelativePath); if (versionDirectory.exists()) { File file = versionDirectory.getFile(); if (file.isFile()) { file.delete();/*from w w w.j a va 2 s .co m*/ } else { FileUtils.deleteDirectory(file); } } }
From source file:org.betaconceptframework.astroboa.test.AstroboaTestContext.java
private void touchResource(String resourceRelativePath) throws IOException { Resource resource = new ClassPathResource(resourceRelativePath); if (resource.exists()) { File file = resource.getFile(); if (file.isFile()) { FileUtils.touch(file);/*from w ww. j a v a 2 s. com*/ } else { File[] files = file.listFiles(); if (files != null && files.length > 0) { for (File child : files) { FileUtils.touch(child); } } } } }
From source file:org.betaconceptframework.astroboa.test.engine.service.TaxonomyServiceTest.java
@Test public void testImportXMLofTaxonomiesProvidedWithTheDistribution() throws IOException { Resource taxonomiesHomeDir = new ClassPathResource("/taxonomies"); Assert.assertTrue(taxonomiesHomeDir.exists(), "Home directory of the taxonomies provided in the distribution does not exist in " + taxonomiesHomeDir.getURI().toString()); File[] taxonomyXmls = taxonomiesHomeDir.getFile().listFiles(new FilenameFilter() { @Override//from ww w. j a v a 2s. com public boolean accept(File dir, String name) { return name != null && name.endsWith(".xml"); } }); Assert.assertTrue(taxonomyXmls.length > 0, "Home directory of the taxonomies provided in the distribution '" + taxonomiesHomeDir.getURI().toString() + "' does not contain any xml file"); for (File taxonomyXML : taxonomyXmls) { Taxonomy taxonomy = taxonomyService.save(FileUtils.readFileToString(taxonomyXML, "UTF-8")); markTaxonomyForRemoval(taxonomy); } }
From source file:org.broadleafcommerce.common.web.resource.resolver.BundleResourceResolver.java
protected void logTraceInformation(Resource bundle) { if (LOG.isTraceEnabled()) { if (bundle == null) { LOG.trace("Resolving bundle, bundle is null"); } else {/* w ww . ja va 2 s . c om*/ LOG.trace("Resolving bundle, bundle is not null, bundle.exists() == " + bundle.exists() + " ,filename = " + bundle.getFilename()); try { LOG.trace("Resolving bundle - File Path" + bundle.getFile().getAbsolutePath()); } catch (IOException e) { LOG.error("IOException debugging bundle code", e); } } } }