Java Code Examples for org.springframework.core.io.Resource#toString()

The following examples show how to use org.springframework.core.io.Resource#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlSessionMapperHotspotLoader.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * Refresh the contents of mybatis mapping files.
 * 
 * @param configuration
 * @throws Exception
 */
private synchronized void refresh(Configuration configuration) throws Exception {
	// 清理Mybatis的所有映射文件缓存, 目前由于未找到清空被修改文件的缓存的key值, 暂时仅支持全部清理, 然后全部加载
	doCleanupOlderCacheConfig(configuration);

	long begin = currentTimeMillis();
	for (Resource rs : mapperLocations) {
		try {
			XMLMapperBuilder builder = new XMLMapperBuilder(rs.getInputStream(), configuration, rs.toString(),
					configuration.getSqlFragments()); // Reload.
			builder.parse();
			log.debug("Refreshed for: {}", rs);
		} catch (IOException e) {
			log.error(format("Failed to refresh mapper for: %s", rs), e);
		}
	}
	long now = currentTimeMillis();
	out.println(format("%s - Refreshed mappers: %s, cost: %sms", new Date(), mapperLocations.length, (now - begin)));

	// Update refresh time.
	lastRefreshTime.set(now);
}
 
Example 2
Source File: Markdown.java    From portal-de-servicos with MIT License 6 votes vote down vote up
@Cacheable("html")
public String toHtml(Resource resource) {
    if (!resource.exists()) {
        throw new ConteudoNaoEncontrado(resource.toString());
    }

    try {
        InputStreamReader input = new InputStreamReader(resource.getInputStream(), "UTF-8");

        try (BufferedReader br = new BufferedReader(input)) {
            String nome = br.readLine();
            String conteudo = nome + "\n" + br.lines().collect(joining("\n"));
            return toHtml(conteudo);
        }
    } catch (IOException e) {
        throw new ConteudoNaoEncontrado(e);
    }
}
 
Example 3
Source File: ConfigurationSummary.java    From ldp4j with Apache License 2.0 6 votes vote down vote up
private String getId(Resource resource) {
	ResourceSource source = getResourceSource(resource);
	String id=resource.toString();
	switch(source) {
		case CLASSPATH:
		case FILE_SYSTEM:
		case REMOTE:
			id=id.substring(id.indexOf("[")+1,id.indexOf("]"));
			break;
		case OSGI_BUNDLE:
			id=id.substring(id.indexOf("[")+1,id.indexOf("]"));
			id=id.split("\\|")[0];
			break;
		case RAW:
		case STREAM:
		case UNKNOWN:
			break;
		default:
			throw new AssertionError("Unsupported resource source '"+source+"'");
	}
	return id;
}
 
Example 4
Source File: MybatisXmlProcess.java    From springboot-plugin-framework-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 加载xml资源
 * @param resources resources
 * @param pluginClassLoader pluginClassLoader
 * @throws Exception Exception
 */
public void loadXmlResource(List<Resource> resources, ClassLoader pluginClassLoader) throws Exception {
    if(resources == null || resources.isEmpty()){
        return;
    }
    Configuration configuration = factory.getConfiguration();
    // removeConfig(configuration);
    ClassLoader defaultClassLoader = Resources.getDefaultClassLoader();
    try {
        Resources.setDefaultClassLoader(pluginClassLoader);
        for (Resource resource :resources) {
            InputStream inputStream = resource.getInputStream();
            try {
                PluginMybatisXmlMapperBuilder xmlMapperBuilder =  new PluginMybatisXmlMapperBuilder(
                        inputStream,
                        configuration, resource.toString(),
                        configuration.getSqlFragments(),
                        pluginClassLoader);
                xmlMapperBuilder.parse();
            } finally {
                if(inputStream != null){
                    inputStream.close();
                }
            }

        }
    } finally {
        ErrorContext.instance().reset();
        Resources.setDefaultClassLoader(defaultClassLoader);
    }
}
 
Example 5
Source File: ConfigurationSummary.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
private String getSource(Resource resource) {
	ResourceSource source = getResourceSource(resource);
	String result=source.getTag();
	if(ResourceSource.OSGI_BUNDLE.equals(source)) {
		String id=resource.toString();
		id=id.substring(id.indexOf("[")+1,id.indexOf("]"));
		String[] parts = id.split("\\|");
		String bundle=parts[1];
		result=result.concat(" (").concat(bundle.split("=")[1]).concat(")");
	}
	return result;
}