org.apache.axiom.om.OMElement.getTextAsStream()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(66)

本文整理了Java中org.apache.axiom.om.OMElement.getTextAsStream()方法的一些代码示例,展示了OMElement.getTextAsStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMElement.getTextAsStream()方法的具体详情如下:
包路径:org.apache.axiom.om.OMElement
类名称:OMElement
方法名:getTextAsStream

OMElement.getTextAsStream介绍

[英]Returns a stream representing the concatenation of the text nodes that are children of a this element. The stream returned by this method produces exactly the same character sequence as the the stream created by the following expression:

new StringReader(element.getText())

The difference is that the stream implementation returned by this method is optimized for performance and is guaranteed to have constant memory usage, provided that:

  1. The method is not required to cache the content of the OMElement, i.e. cache is false or the element is an OMSourcedElement that is backed by a non destructive OMDataSource.
  2. The underlying parser (or the implementation of the underlying XMLStreamReader in the case of an OMSourcedElement) is non coalescing. Note that this is not the default in Axiom and it may be necessary to configure the parser with StAXParserConfiguration#NON_COALESCING.

When this method is used with cache set to false the caller must close the returned stream before attempting to access other nodes in the tree.
[中]返回一个流,该流表示作为this元素的子元素的文本节点的串联。此方法返回的流产生的字符序列与以下表达式创建的流完全相同:

new StringReader(element.getText())

不同之处在于,此方法返回的流实现针对性能进行了优化,并保证具有恒定的内存使用率,前提是:
1.缓存OmeElement的内容不需要该方法,即cachefalse或该元素是由非破坏性OMDataSource支持的OmSourceElement。
1.底层解析器(或者对于OMSourceElement,底层XMLStreamReader的实现)是非合并的。请注意,这不是Axiom中的默认设置,可能需要使用StAXParserConfiguration#非#合并来配置解析器。
当此方法与设置为false的缓存一起使用时,调用方必须在尝试访问树中的其他节点之前关闭返回的流。

代码示例

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * @deprecated Use {@link OMElement#getTextAsStream(boolean)} instead.
 */
public static Reader getTextAsStream(OMElement element, boolean cache) {
  return element.getTextAsStream(cache);
}

代码示例来源:origin: org.apache.axis2/axis2-transport-base

public InputStream getInputStream() throws IOException {
  return new ReaderInputStream(element.getTextAsStream(true), charset);
}

代码示例来源:origin: apache/axis2-java

public InputStream getInputStream() throws IOException {
  return new ReaderInputStream(element.getTextAsStream(true), charset);
}

相关文章

微信公众号

最新文章

更多