Search in sources :

Example 91 with Resource

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);
            }
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(org.springframework.core.io.Resource) Map(java.util.Map) IOException(java.io.IOException)

Example 92 with Resource

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;
}
Also used : Resource(org.springframework.core.io.Resource) HashSet(java.util.HashSet)

Example 93 with Resource

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;
}
Also used : Config(io.servicecomb.core.handler.config.Config) Resource(org.springframework.core.io.Resource)

Example 94 with Resource

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()));
    }
}
Also used : IncConfig(io.servicecomb.foundation.common.config.impl.IncConfigs.IncConfig) IncConfigs(io.servicecomb.foundation.common.config.impl.IncConfigs) Resource(org.springframework.core.io.Resource) XmlLoader(io.servicecomb.foundation.common.config.impl.XmlLoader) PropertiesLoader(io.servicecomb.foundation.common.config.impl.PropertiesLoader)

Example 95 with Resource

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;
}
Also used : Resource(org.springframework.core.io.Resource) Properties(java.util.Properties)

Aggregations

Resource (org.springframework.core.io.Resource)610 Test (org.junit.Test)257 ClassPathResource (org.springframework.core.io.ClassPathResource)231 IOException (java.io.IOException)103 FileSystemResource (org.springframework.core.io.FileSystemResource)77 UrlResource (org.springframework.core.io.UrlResource)68 File (java.io.File)64 ArrayList (java.util.ArrayList)58 ByteArrayResource (org.springframework.core.io.ByteArrayResource)49 InputStream (java.io.InputStream)46 InputStreamResource (org.springframework.core.io.InputStreamResource)31 PathMatchingResourcePatternResolver (org.springframework.core.io.support.PathMatchingResourcePatternResolver)30 URL (java.net.URL)25 HashMap (java.util.HashMap)20 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)18 ServletContextResource (org.springframework.web.context.support.ServletContextResource)18 Map (java.util.Map)17 ResourcePatternResolver (org.springframework.core.io.support.ResourcePatternResolver)17 ResourceLoader (org.springframework.core.io.ResourceLoader)16 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)16