本文整理汇总了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);
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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;
}