use of org.springframework.core.io.support.ResourcePatternResolver in project nd4j by deeplearning4j.
the class TFGraphTestAllHelper method readVars.
protected static Map<String, INDArray> readVars(String modelName, String base_dir, String pattern) throws IOException {
Map<String, INDArray> varMap = new HashMap<>();
String modelDir = base_dir + "/" + modelName;
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new ClassPathResource(modelDir).getClassLoader());
Resource[] resources = resolver.getResources("classpath*:" + modelDir + "/" + pattern + ".shape");
val dtype = Nd4j.dataType();
for (int i = 0; i < resources.length; i++) {
String fileName = resources[i].getFilename();
String varPath = modelDir + "/" + fileName;
String[] varNameArr = fileName.split("\\.");
String varName = String.join(".", Arrays.copyOfRange(varNameArr, 0, varNameArr.length - 2));
int[] varShape = Nd4j.readNumpy(new ClassPathResource(varPath).getInputStream(), ",").data().asInt();
try {
float[] varContents = Nd4j.readNumpy(new ClassPathResource(varPath.replace(".shape", ".csv")).getInputStream(), ",").data().asFloat();
INDArray varValue;
if (varShape.length == 1) {
if (varShape[0] == 0) {
varValue = Nd4j.trueScalar(varContents[0]);
} else {
varValue = Nd4j.trueVector(varContents);
}
} else {
varValue = Nd4j.create(varContents, varShape);
}
// varValue = Nd4j.readNumpy(new ClassPathResource(varPath.replace(".shape", ".csv")).getInputStream(), ",").reshape(varShape);
if (varName.contains("____")) {
// these are intermediate node outputs
varMap.put(varName.replaceAll("____", "/"), varValue);
} else {
varMap.put(varName, varValue);
}
} catch (NumberFormatException e) {
// FIXME: we can't parse boolean arrays right now :(
continue;
}
}
return varMap;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project nd4j by deeplearning4j.
the class TFGraphTestAllHelper method modelDirNames.
private static String[] modelDirNames(String base_dir, ExecuteWith executeWith) throws IOException {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(new ClassPathResource(base_dir).getClassLoader());
Resource[] resources = resolver.getResources("classpath*:" + base_dir + "/**/frozen_model.pb");
String[] exampleNames = new String[resources.length];
for (int i = 0; i < resources.length; i++) {
String nestedName = resources[i].getURL().toString().split(base_dir + "/")[1];
exampleNames[i] = nestedName.replaceAll(Pattern.quote(executeWith.getDefaultBaseDir()), "").replaceAll("/frozen_model.pb", "");
}
return exampleNames;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project service-proxy by membrane.
the class ClassFinder method find.
public static List<Class<?>> find(ClassLoader loader, String scannedPackage) throws IOException, ClassNotFoundException {
String scannedPath = scannedPackage.replace(PKG_SEPARATOR, DIR_SEPARATOR);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(loader);
Resource[] resources = resolver.getResources("classpath:" + scannedPath + "/*");
List<Class<?>> classes = new ArrayList<Class<?>>();
for (Resource resource : resources) {
String filename = resource.getFilename();
Class clazz = getClasses(resolver, scannedPackage, filename);
if (clazz != null)
classes.add(clazz);
}
return classes;
}
use of org.springframework.core.io.support.ResourcePatternResolver in project openmrs-core by openmrs.
the class MutableResourceBundleMessageSource method findPropertiesFiles.
/**
* Searches the filesystem for message properties files. ABKTODO: consider caching this, rather
* than searching every time
*
* @return an array of property file names
*/
private Resource[] findPropertiesFiles() {
Set<Resource> resourceSet = new HashSet<>();
try {
String pattern = "classpath*:messages*.properties";
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver(OpenmrsClassLoader.getInstance());
Resource[] propertiesFiles = resourceResolver.getResources(pattern);
Collections.addAll(resourceSet, propertiesFiles);
for (ModuleClassLoader moduleClassLoader : ModuleFactory.getModuleClassLoaders()) {
resourceResolver = new PathMatchingResourcePatternResolver(moduleClassLoader);
propertiesFiles = resourceResolver.getResources(pattern);
Collections.addAll(resourceSet, propertiesFiles);
}
} catch (IOException e) {
log.error("Error generated", e);
}
if (log.isWarnEnabled() && (resourceSet.isEmpty())) {
log.warn("No properties files found.");
}
return resourceSet.toArray(new Resource[resourceSet.size()]);
}
use of org.springframework.core.io.support.ResourcePatternResolver in project jeesuite-libs by vakinge.
the class SchedulerFactoryBeanWrapper method scanAndRegisterAnnotationJobs.
private void scanAndRegisterAnnotationJobs(String[] scanBasePackages) {
String RESOURCE_PATTERN = "/**/*.class";
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
for (String scanBasePackage : scanBasePackages) {
logger.info(">>begin scan package [{}] with Annotation[ScheduleConf] jobs ", scanBasePackage);
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(scanBasePackage) + RESOURCE_PATTERN;
org.springframework.core.io.Resource[] resources = resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(resourcePatternResolver);
for (org.springframework.core.io.Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
Class<?> clazz = Class.forName(className);
if (clazz.isAnnotationPresent(ScheduleConf.class)) {
ScheduleConf annotation = clazz.getAnnotation(ScheduleConf.class);
AbstractJob job = (AbstractJob) context.getBean(clazz);
job.setCronExpr(annotation.cronExpr());
job.setExecuteOnStarted(annotation.executeOnStarted());
job.setGroup(groupName);
job.setJobName(annotation.jobName());
job.setRetries(annotation.retries());
if (!schedulers.contains(job)) {
schedulers.add(job);
logger.info("register new job:{}", ToStringBuilder.reflectionToString(job, ToStringStyle.JSON_STYLE));
} else {
logger.info("Job[{}] is registered", job.getJobName());
}
}
}
}
logger.info("<<scan package[" + scanBasePackage + "] finished!");
} catch (Exception e) {
if (e instanceof org.springframework.beans.factory.NoSuchBeanDefinitionException) {
throw (org.springframework.beans.factory.NoSuchBeanDefinitionException) e;
}
logger.error("<<scan package[" + scanBasePackage + "] error", e);
}
}
}
Aggregations