从OMElement对象获取InputStream / io.Reader

[英]Get an InputStream/io.Reader from OMElement object


I have a OMElement object and from that I want to get an InputStream or reader object. What I want is to stream the xml from the OMElement which I have, without getting loaded into memory. I only could be able to get XMLStreamReader object from that. But I can't find a way to get InputStream/Reader out of that.

我有一个OMElement对象,我希望得到一个InputStream或reader对象。我想要的是从我拥有的OMElement流式传输xml,而不是加载到内存中。我只能从中获取XMLStreamReader对象。但我无法找到一种方法来获取InputStream / Reader。

OMElement element /*I have this object */
XMLStreamReader xmlreader = element.getXMLStreamReaderWithoutCaching();

Can anyone please help me ? I really appreciate!

谁能帮帮我吗 ?我真的很感激!

Thanks

谢谢

PS: I have come a way to get an InputStream but it gives an exception which I need help to resolve it.

PS:我已经找到了一个获取InputStream的方法,但它提供了一个异常,我需要帮助来解决它。

XMLStreamReader xmlReader = element.getXMLStreamReader(false);

  try {
      if (xmlReader.getEventType() == XMLStreamReader.START_DOCUMENT) {
                xmlReader.next();
       }
      DataHandler handler = XMLStreamReaderUtils.getDataHandlerFromElement(xmlReader);
      handler.getInputStream();

The call to getDataHandlerFromElement generate the exception javax.xml.stream.XMLStreamException: Error during base64 decoding

对getDataHandlerFromElement的调用生成异常javax.xml.stream.XMLStreamException:base64解码期间出错

1 个解决方案

#1


2  

The purpose of the getDataHandlerFromElement method is to decode base64 encoded binary data contained in an element, which is not what you want.

getDataHandlerFromElement方法的目的是解码元素中包含的base64编码二进制数据,这不是您想要的。

Axiom currently doesn't have a streaming pull serializer (and I don't know any other XML library that supports this). It only supports serializing to XML in push mode, i.e. by writing to an OutputStream or Writer. You could do the serialization in a separate thread and use a PipedOutputStream/PipedInputStream (similar to what Activation does for DataHandler#getInputStream() for a DataHandler that is not backed by a DataSource). This would satisfy the constant memory requirement, but I guess that the overhead caused by using a separate thread would not be acceptable in your case.

Axiom目前没有流式拉线序器(我不知道任何其他支持这种情况的XML库)。它仅支持在推模式下序列化为XML,即通过写入OutputStream或Writer。您可以在单独的线程中进行序列化,并使用PipedOutputStream / PipedInputStream(类似于Activation为DataHource支持的DataHandler的DataHandler#getInputStream()所做的操作)。这将满足常量内存要求,但我想在您的情况下使用单独的线程所导致的开销是不可接受的。

I thought about the possibility to implement such a pull serializer in the past, and I think it's technically feasible to do that (without using a separate thread). Please open a feature request for Axiom so that we can implement that in one of the next releases. I think it would be an interesting addition to Axiom.

我想过在过去实现这种拉序列化器的可能性,我认为这样做(不使用单独的线程)在技术上是可行的。请打开Axiom的功能请求,以便我们可以在下一个版本中实现它。我认为这对Axiom来说是一个有趣的补充。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/11/22/5c0c711d06544aa88d8c06f7a9b658c7.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告