use of org.springframework.core.io.support.ResourcePatternResolver in project OpenClinica by OpenClinica.
the class CoreResources method copyConfig.
private void copyConfig() throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
Resource[] resources = null;
FileOutputStream out = null;
Resource resource1 = null;
Resource resource2 = null;
resource1 = resolver.getResource("classpath:datainfo.properties");
resource2 = resolver.getResource("classpath:extract.properties");
String filePath = "$catalina.home/$WEBAPP.lower.config";
filePath = replaceWebapp(filePath);
filePath = replaceCatHome(filePath);
File dest = new File(filePath);
if (!dest.exists()) {
if (!dest.mkdirs()) {
throw new OpenClinicaSystemException("Copying files, Could not create directory: " + dest.getAbsolutePath() + ".");
}
}
File f1 = new File(dest, resource1.getFilename());
File f2 = new File(dest, resource2.getFilename());
if (!f1.exists()) {
out = new FileOutputStream(f1);
IOUtils.copy(resource1.getInputStream(), out);
out.close();
}
if (!f2.exists()) {
out = new FileOutputStream(f2);
IOUtils.copy(resource2.getInputStream(), out);
out.close();
}
/*
*
* for (Resource r: resources) { File f = new File(dest, r.getFilename()); if(!f.exists()){ out = new
* FileOutputStream(f); IOUtils.copy(r.getInputStream(), out); out.close(); } }
*/
}
use of org.springframework.core.io.support.ResourcePatternResolver in project cxf by apache.
the class SpringClasspathScanner method findResourcesInternal.
@Override
protected List<URL> findResourcesInternal(Collection<String> basePackages, String extension, ClassLoader loader) throws IOException {
final List<URL> resourceURLs = new ArrayList<>();
if (basePackages == null || basePackages.isEmpty()) {
return resourceURLs;
}
ResourcePatternResolver resolver = getResolver(loader);
for (final String basePackage : basePackages) {
final boolean scanAllPackages = basePackage.equals(WILDCARD);
String theBasePackage = basePackage;
if (theBasePackage.startsWith(CLASSPATH_URL_SCHEME)) {
theBasePackage = theBasePackage.substring(CLASSPATH_URL_SCHEME.length());
}
final String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + (scanAllPackages ? "" : basePackage.contains(WILDCARD) ? basePackage : ClassUtils.convertClassNameToResourcePath(theBasePackage)) + ALL_FILES + "." + extension;
final Resource[] resources = resolver.getResources(packageSearchPath);
for (final Resource resource : resources) {
resourceURLs.add(resource.getURL());
}
}
return resourceURLs;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project web3sdk by FISCO-BCOS.
the class PEMManager method load.
public void load() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, NoSuchProviderException, InvalidKeySpecException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource pemResources = resolver.getResource(pemFile);
load(pemResources.getInputStream());
}
use of org.springframework.core.io.support.ResourcePatternResolver in project dq-easy-cloud by dq-open-cloud.
the class EcDataSourceConfig method sqlSessionFactory.
@Bean
public SqlSessionFactory sqlSessionFactory(DataSource dataSourece) throws Exception {
// 添加XML目录
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(dataSourece);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
sessionFactory.setMapperLocations(resolver.getResources(mapperLocations));
return sessionFactory.getObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
use of org.springframework.core.io.support.ResourcePatternResolver in project littlefisher-system by littlefishercoder.
the class PackageUtil method scanTypePackage.
/**
* 扫描获取指定包路径所有类
*
* @param typePackage 扫描类包路径
* @return Set<Class>
*/
public static Set<Class> scanTypePackage(String typePackage) {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(resolver);
String pkg = ClassUtils.convertClassNameToResourcePath(typePackage) + ".class";
/*
* 将加载多个绝对匹配的所有Resource
* 将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分,然后进行遍历模式匹配,排除重复包路径
*/
try {
Set<Class> set = Sets.newHashSet();
Resource[] resources = resolver.getResources(pkg);
if (ArrayUtils.isNotEmpty(resources)) {
MetadataReader metadataReader;
for (Resource resource : resources) {
if (resource.isReadable()) {
metadataReader = metadataReaderFactory.getMetadataReader(resource);
set.add(Class.forName(metadataReader.getClassMetadata().getClassName()));
}
}
}
return set;
} catch (Exception e) {
throw new BaseAppException("CORE-000007", null, e);
}
}
Aggregations