当前位置: 首页>>代码示例>>Java>>正文


Java EncodedResource.getEncoding方法代码示例

本文整理汇总了Java中org.springframework.core.io.support.EncodedResource.getEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java EncodedResource.getEncoding方法的具体用法?Java EncodedResource.getEncoding怎么用?Java EncodedResource.getEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.core.io.support.EncodedResource的用法示例。


在下文中一共展示了EncodedResource.getEncoding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadBeanDefinitions

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Load bean definitions from the specified properties file.
 * @param encodedResource the resource descriptor for the properties file,
 * allowing to specify an encoding to use for parsing the file
 * @param prefix a filter within the keys in the map: e.g. 'beans.'
 * (can be empty or {@code null})
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource, String prefix)
		throws BeanDefinitionStoreException {

	Properties props = new Properties();
	try {
		InputStream is = encodedResource.getResource().getInputStream();
		try {
			if (encodedResource.getEncoding() != null) {
				getPropertiesPersister().load(props, new InputStreamReader(is, encodedResource.getEncoding()));
			}
			else {
				getPropertiesPersister().load(props, is);
			}
		}
		finally {
			is.close();
		}
		return registerBeanDefinitions(props, prefix, encodedResource.getResource().getDescription());
	}
	catch (IOException ex) {
		throw new BeanDefinitionStoreException("Could not parse properties from " + encodedResource.getResource(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:PropertiesBeanDefinitionReader.java

示例2: loadBeanDefinitions

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Load bean definitions from the specified XML file.
 * @param encodedResource the resource descriptor for the XML file,
 * allowing to specify an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
	Assert.notNull(encodedResource, "EncodedResource must not be null");
	if (logger.isInfoEnabled()) {
		logger.info("Loading XML bean definitions from " + encodedResource.getResource());
	}

	Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get();
	if (currentResources == null) {
		currentResources = new HashSet<EncodedResource>(4);
		this.resourcesCurrentlyBeingLoaded.set(currentResources);
	}
	if (!currentResources.add(encodedResource)) {
		throw new BeanDefinitionStoreException(
				"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
	}
	try {
		InputStream inputStream = encodedResource.getResource().getInputStream();
		try {
			InputSource inputSource = new InputSource(inputStream);
			if (encodedResource.getEncoding() != null) {
				inputSource.setEncoding(encodedResource.getEncoding());
			}
			return doLoadBeanDefinitions(inputSource, encodedResource.getResource());
		}
		finally {
			inputStream.close();
		}
	}
	catch (IOException ex) {
		throw new BeanDefinitionStoreException(
				"IOException parsing XML document from " + encodedResource.getResource(), ex);
	}
	finally {
		currentResources.remove(encodedResource);
		if (currentResources.isEmpty()) {
			this.resourcesCurrentlyBeingLoaded.remove();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:XmlBeanDefinitionReader.java

示例3: loadBeanDefinitions

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Load bean definitions from the specified XML file.
 * @param encodedResource the resource descriptor for the XML file,
 * allowing to specify an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 */
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
	Assert.notNull(encodedResource, "EncodedResource must not be null");
	if (logger.isInfoEnabled()) {
		logger.info("Loading XML bean definitions from " + encodedResource.getResource());
	}

	Set<EncodedResource> currentResources = this.resourcesCurrentlyBeingLoaded.get();
	if (currentResources == null) {
		currentResources = new HashSet<EncodedResource>(4);
		this.resourcesCurrentlyBeingLoaded.set(currentResources);
	}
	if (!currentResources.add(encodedResource)) {
		throw new BeanDefinitionStoreException(
				"Detected cyclic loading of " + encodedResource + " - check your import definitions!");
	}
	try {
		InputStream inputStream = encodedResource.getResource().getInputStream();
		try {
			InputSource inputSource = new InputSource(inputStream);
			if (encodedResource.getEncoding() != null) {
				inputSource.setEncoding(encodedResource.getEncoding());
			}
			return doLoadBeanDefinitions(inputSource, encodedResource.getResource()); // 加载BeanDefinition
		}
		finally {
			inputStream.close();
		}
	}
	catch (IOException ex) {
		throw new BeanDefinitionStoreException(
				"IOException parsing XML document from " + encodedResource.getResource(), ex);
	}
	finally {
		currentResources.remove(encodedResource);
		if (currentResources.isEmpty()) {
			this.resourcesCurrentlyBeingLoaded.remove();
		}
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:47,代码来源:XmlBeanDefinitionReader.java

示例4: loadDocument

import org.springframework.core.io.support.EncodedResource; //导入方法依赖的package包/类
/**
 * Loads the <code>Document</code> from the specified
 * {@link org.springframework.core.io.Resource Resource}.
 * 
 * @param res
 *            the resource to load the {@link Document} from
 * 
 * @return the <code>Document</code> specified by the passed
 *         <code>Resource</code>
 */
protected Document loadDocument(
		final org.springframework.core.io.Resource res) {

	// get the resource as encoded one
	final EncodedResource encRes = new EncodedResource(res);

	// read the XML document and replace the placeholders
	InputStream inputStream = null;
	InputSource inputSource = null;
	Document doc = null;
	try {
		inputStream = encRes.getResource().getInputStream();
		inputSource = new InputSource(inputStream);
		if (encRes.getEncoding() != null) {
			inputSource.setEncoding(encRes.getEncoding());
		}

		// get the Document
		final DefaultDocumentLoader loader = new DefaultDocumentLoader();
		doc = loader.loadDocument(inputSource, null, null,
				XmlValidationModeDetector.VALIDATION_NONE, false);
	} catch (final Exception e) {

		// log it
		if (LOG.isWarnEnabled()) {
			LOG.warn(
					"Unable to parse the passed ByteArrayResource '"
							+ res.getDescription() + "'.", e);
		}

		throw new IllegalArgumentException(
				"The passed resource contains an invalid document.", e);
	} finally {

		// close the streams
		Streams.closeIO(inputSource);
		Streams.closeIO(inputStream);
	}

	return doc;
}
 
开发者ID:pmeisen,项目名称:gen-sbconfigurator,代码行数:52,代码来源:DefaultConfiguration.java


注:本文中的org.springframework.core.io.support.EncodedResource.getEncoding方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。