use of org.springframework.core.io.Resource in project opennms by OpenNMS.
the class ZipSystemReportFormatter method write.
@Override
public void write(final SystemReportPlugin plugin) {
final String name = plugin.getName() + ".txt";
try {
createDirectory("");
} catch (final Exception e) {
LOG.error("Unable to create entry '{}'", name, e);
return;
}
if (hasDisplayable(plugin)) {
try {
createEntry(name);
} catch (final Exception e) {
LOG.error("Unable to create entry '{}'", name, e);
return;
}
final AbstractSystemReportFormatter formatter = new TextSystemReportFormatter();
formatter.setOutputStream(m_zipOutputStream);
formatter.begin();
formatter.write(plugin);
formatter.end();
}
byte[] buf = new byte[1024];
for (final Map.Entry<String, Resource> entry : plugin.getEntries().entrySet()) {
final Resource resource = entry.getValue();
if (isFile(resource)) {
try {
createDirectory(plugin.getName());
} catch (final Exception e) {
LOG.error("Unable to create directory '{}'", plugin.getName(), e);
return;
}
final String entryName = String.format("%s/%s", plugin.getName(), entry.getKey());
try {
createEntry(entryName);
} catch (final Exception e) {
LOG.error("Unable to create entry '{}'", entryName, e);
return;
}
InputStream is = null;
try {
is = resource.getInputStream();
int len;
while ((len = is.read(buf)) > 0) {
m_zipOutputStream.write(buf, 0, len);
}
} catch (Throwable e) {
LOG.warn("Unable to read resource '{}'", resource, e);
return;
} finally {
IOUtils.closeQuietly(is);
}
}
}
}
use of org.springframework.core.io.Resource in project java-chassis by ServiceComb.
the class ConsumerSchemaFactory method findLocalSchemas.
protected Set<String> findLocalSchemas(MicroserviceMeta microserviceMeta) {
String resPath = generateSchemaPath(microserviceMeta.getName(), "*");
Resource[] resArr = PaaSResourceUtils.getResources("classpath*:" + resPath);
Set<String> schemaIds = new HashSet<>();
for (Resource res : resArr) {
String schemaId = FilenameUtils.getBaseName(res.getFilename());
schemaIds.add(schemaId);
}
LOGGER.info("Found schema ids local, {}:{}:{}", microserviceMeta.getAppId(), microserviceMeta.getName(), schemaIds);
return schemaIds;
}
use of org.springframework.core.io.Resource in project java-chassis by ServiceComb.
the class HandlerConfigUtils method loadConfig.
private static Config loadConfig() throws Exception {
Config config = new Config();
List<Resource> resList = PaaSResourceUtils.getSortedResources("classpath*:config/cse.handler.xml", ".handler.xml");
for (Resource res : resList) {
Config tmpConfig = XmlLoaderUtils.load(res, Config.class);
config.mergeFrom(tmpConfig);
}
return config;
}
use of org.springframework.core.io.Resource in project java-chassis by ServiceComb.
the class ConfigMgr method init.
public void init() throws Exception {
List<Resource> resArr = PaaSResourceUtils.getSortedResources("classpath*:config/config.inc.xml", ".inc.xml");
IncConfigs incConfigs = new IncConfigs();
incConfigs.setPropertiesList(new ArrayList<>());
incConfigs.setXmlList(new ArrayList<>());
for (Resource resource : resArr) {
IncConfigs tmp = XmlLoaderUtils.load(resource, IncConfigs.class);
if (tmp.getPropertiesList() != null) {
incConfigs.getPropertiesList().addAll(tmp.getPropertiesList());
}
if (tmp.getXmlList() != null) {
incConfigs.getXmlList().addAll(tmp.getXmlList());
}
}
configLoaderMap = new HashMap<>();
for (IncConfig incConfig : incConfigs.getPropertiesList()) {
PropertiesLoader loader = (PropertiesLoader) configLoaderMap.get(incConfig.getId());
if (loader != null) {
loader.getLocationPatternList().addAll(incConfig.getPathList());
continue;
}
configLoaderMap.put(incConfig.getId(), new PropertiesLoader(incConfig.getPathList()));
}
for (IncConfig incConfig : incConfigs.getXmlList()) {
XmlLoader loader = (XmlLoader) configLoaderMap.get(incConfig.getId());
if (loader != null) {
loader.getLocationPatternList().addAll(incConfig.getPathList());
continue;
}
configLoaderMap.put(incConfig.getId(), new XmlLoader(incConfig.getPathList()));
}
}
use of org.springframework.core.io.Resource in project java-chassis by ServiceComb.
the class PropertiesLoader method load.
@SuppressWarnings("unchecked")
@Override
public <T> T load() throws Exception {
Properties props = new Properties();
for (String locationPattern : locationPatternList) {
List<Resource> resList = PaaSResourceUtils.getSortedPorperties(locationPattern);
foundResList.addAll(resList);
PaaSPropertiesLoaderUtils.fillAllProperties(props, resList);
}
return (T) props;
}
Aggregations