List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.jspringbot.keyword.db.DbHelper.java
public void init() { ResourceEditor editor = new ResourceEditor(); editor.setAsText("classpath:db-queries/"); Resource dbDirResource = (Resource) editor.getValue(); boolean hasDBDirectory = true; boolean hasDBProperties = true; if (dbDirResource != null) { try {//w w w. j a v a2s . c o m File configDir = dbDirResource.getFile(); if (configDir.isDirectory()) { File[] propertiesFiles = configDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml"); } }); for (File propFile : propertiesFiles) { addExternalQueries(propFile); } } } catch (IOException ignore) { hasDBDirectory = false; } } editor.setAsText("classpath:db-queries.properties"); Resource dbPropertiesResource = (Resource) editor.getValue(); if (dbPropertiesResource != null) { try { if (dbPropertiesResource.getFile().isFile()) { addExternalQueries(dbPropertiesResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } editor.setAsText("classpath:db-queries.xml"); Resource dbXMLResource = (Resource) editor.getValue(); if (dbXMLResource != null && !hasDBProperties) { try { if (dbXMLResource.getFile().isFile()) { addExternalQueries(dbXMLResource.getFile()); } } catch (IOException e) { hasDBProperties = false; } } if (!hasDBDirectory && !hasDBProperties) { LOGGER.warn("No query sources found."); } begin(); }
From source file:edu.jhuapl.openessence.config.AppInitializer.java
private List<PropertySource<?>> getPropertySources(Collection<Resource> resources) { List<PropertySource<?>> propertySources = new ArrayList<PropertySource<?>>(); for (Resource r : resources) { String filename = r.getFilename(); if (filename == null) { throw new IllegalArgumentException("Cannot have resource with no file"); }/*from ww w . j av a 2 s . co m*/ String name = FilenameUtils.getBaseName(r.getFilename()); Properties source; try { source = PropertiesLoaderUtils.loadProperties(r); } catch (IOException e) { throw new IllegalStateException(e); } propertySources.add(new PropertiesPropertySource(name, source)); try { log.info("Adding file {} as property source named '{}'", r.getFile(), name); } catch (IOException e) { throw new IllegalStateException(e); } } return propertySources; }
From source file:com.thoughtworks.go.http.mocks.MockServletContext.java
@Override public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try {/*from w w w .j a v a 2 s.c o m*/ File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { logger.warn("Couldn't get resource paths for " + resource, ex); return null; } }
From source file:net.paoding.rose.scanner.ModuleResourceProviderImpl.java
@Override public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException { Local local = new Local(); String[] controllersScope = scope.getScope("controllers"); if (logger.isInfoEnabled()) { logger.info("[moduleResource] starting ..."); logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "// + Arrays.toString(controllersScope)); }/*from w w w. j a v a 2 s .c o m*/ List<ResourceRef> refers = RoseScanner.getInstance().getJarOrClassesFolderResources(controllersScope); if (logger.isInfoEnabled()) { logger.info("[moduleResource] exits from 'findFiles'"); logger.info( "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers); } FileSystemManager fileSystem = new FileSystemManager(); for (ResourceRef refer : refers) { Resource resource = refer.getResource(); if (!refer.hasModifier("controllers")) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not marked as 'controllers'" + " in META-INF/rose.properties or META-INF/MANIFEST.MF: " + resource.getURI()); } continue; } File resourceFile = resource.getFile(); String urlString; if ("jar".equals(refer.getProtocol())) { urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI() + ResourceUtils.JAR_URL_SEPARATOR; } else { urlString = resourceFile.toURI().toString(); } FileObject rootObject = fileSystem.resolveFile(urlString); if (rootObject == null || !rootObject.exists()) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not exists: " + urlString); } continue; } if (logger.isInfoEnabled()) { logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject); } try { int oldSize = local.moduleResourceList.size(); deepScanImpl(local, rootObject, rootObject); int newSize = local.moduleResourceList.size(); if (logger.isInfoEnabled()) { logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject); } } catch (Exception e) { logger.error("[moduleResource] error happend when scanning " + rootObject, e); } fileSystem.clearCache(); } afterScanning(local); logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources "); return local.moduleResourceList; }
From source file:com.laxser.blitz.scanner.ModuleResourceProviderImpl.java
@Override public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException { Local local = new Local(); String[] controllersScope = scope.getScope("controllers"); if (logger.isInfoEnabled()) { logger.info("[moduleResource] starting ..."); logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "// + Arrays.toString(controllersScope)); }/*w ww . j a v a 2 s . c om*/ List<ResourceRef> refers = BlitzScanner.getInstance().getJarOrClassesFolderResources(controllersScope); if (logger.isInfoEnabled()) { logger.info("[moduleResource] exits from 'findFiles'"); logger.info( "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers); } FileSystemManager fileSystem = new FileSystemManager(); for (ResourceRef refer : refers) { Resource resource = refer.getResource(); if (!refer.hasModifier("controllers")) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not marked as 'controllers'" + " in META-INF/blitz.properties or META-INF/MANIFEST.MF: " + resource.getURI()); } continue; } File resourceFile = resource.getFile(); String urlString; if ("jar".equals(refer.getProtocol())) { urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI() + ResourceUtils.JAR_URL_SEPARATOR; } else { urlString = resourceFile.toURI().toString(); } FileObject rootObject = fileSystem.resolveFile(urlString); if (rootObject == null || !rootObject.exists()) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not exists: " + urlString); } continue; } if (logger.isInfoEnabled()) { logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject); } try { int oldSize = local.moduleResourceList.size(); deepScanImpl(local, rootObject, rootObject); int newSize = local.moduleResourceList.size(); if (logger.isInfoEnabled()) { logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject); } } catch (Exception e) { logger.error("[moduleResource] error happend when scanning " + rootObject, e); } fileSystem.clearCache(); } afterScanning(local); logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources "); return local.moduleResourceList; }
From source file:org.fao.fenix.wds.core.utils.Wrapper.java
public Wrapper(Resource excel) throws WDSException { try {//w w w . ja v a2 s . com this.setExcelPath(excel.getFile().getPath()); } catch (IOException e) { throw new WDSException(e.getMessage()); } }
From source file:com.sinosoft.one.mvc.scanner.ModuleResourceProviderImpl.java
public List<ModuleResource> findModuleResources(LoadScope scope) throws IOException { Local local = new Local(); String[] controllersScope = scope.getScope("controllers"); if (logger.isInfoEnabled()) { logger.info("[moduleResource] starting ..."); logger.info("[moduleResource] call 'findFiles':" + " to find classes or jar files by scope "// + Arrays.toString(controllersScope)); }/*w ww.j a v a 2 s .c o m*/ List<ResourceRef> refers = MvcScanner.getInstance().getJarOrClassesFolderResources(controllersScope); if (logger.isInfoEnabled()) { logger.info("[moduleResource] exits from 'findFiles'"); logger.info( "[moduleResource] going to scan controllers" + " from these folders or jar files:" + refers); } FileSystemManager fileSystem = new FileSystemManager(); for (ResourceRef refer : refers) { Resource resource = refer.getResource(); if (!refer.hasModifier("controllers")) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not marked as 'controllers'" + " in META-INF/mvc.properties or META-INF/MANIFEST.MF: " + resource.getURI()); } continue; } File resourceFile = resource.getFile(); String urlString; if ("jar".equals(refer.getProtocol())) { urlString = ResourceUtils.URL_PROTOCOL_JAR + ":" + resourceFile.toURI() + ResourceUtils.JAR_URL_SEPARATOR; } else { urlString = resourceFile.toURI().toString(); } FileObject rootObject = fileSystem.resolveFile(urlString); if (rootObject == null || !rootObject.exists()) { if (logger.isDebugEnabled()) { logger.debug("[moduleResource] Ignored because not exists: " + urlString); } continue; } if (logger.isInfoEnabled()) { logger.info("[moduleResource] start to scan moduleResource in file: " + rootObject); } try { int oldSize = local.moduleResourceList.size(); deepScanImpl(local, rootObject, rootObject); int newSize = local.moduleResourceList.size(); if (logger.isInfoEnabled()) { logger.info("[moduleResource] got " + (newSize - oldSize) + " modules in " + rootObject); } } catch (Exception e) { logger.error("[moduleResource] error happend when scanning " + rootObject, e); } fileSystem.clearCache(); } afterScanning(local); logger.info("[moduleResource] found " + local.moduleResourceList.size() + " module resources "); return local.moduleResourceList; }
From source file:com.epam.catgenome.manager.GffManagerTest.java
private String readFile(String filename) throws IOException { Resource resource = context.getResource("classpath:externaldb//data//" + filename); String pathStr = resource.getFile().getPath(); return new String(Files.readAllBytes(Paths.get(pathStr)), Charset.defaultCharset()); }
From source file:com.epam.catgenome.manager.bam.BamManagerTest.java
private void registerFileWithoutSOTag(String path) throws IOException { Resource resource = context.getResource(path); IndexedFileRegistrationRequest request = new IndexedFileRegistrationRequest(); request.setPath(resource.getFile().getAbsolutePath()); request.setIndexPath(resource.getFile().getAbsolutePath() + BAI_EXTENSION); request.setName(TEST_NSAME);/*from ww w . j a va 2s . c om*/ request.setReferenceId(testReference.getId()); request.setType(BiologicalDataItemResourceType.FILE); bamManager.registerBam(request); }
From source file:com.epam.catgenome.manager.ProjectManagerTest.java
private VcfFile addVcfFile(String name, String path) throws IOException, InterruptedException, NoSuchAlgorithmException, VcfReadingException { Resource resource = context.getResource(path); FeatureIndexedFileRegistrationRequest request = new FeatureIndexedFileRegistrationRequest(); request.setReferenceId(referenceId); request.setName(name);/*from w w w . j ava2s . co m*/ request.setPath(resource.getFile().getAbsolutePath()); return vcfManager.registerVcfFile(request); }