简体   繁体   English

从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. 我有一个OMElement对象,我希望得到一个InputStream或reader对象。 What I want is to stream the xml from the OMElement which I have, without getting loaded into memory. 我想要的是从我拥有的OMElement流式传输xml ,而不是加载到内存中。 I only could be able to get XMLStreamReader object from that. 我只能从中获取XMLStreamReader对象。 But I can't find a way to get InputStream/Reader out of that. 但我无法找到一种方法来获取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解码期间出错

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). Axiom目前没有流式拉线序器(我不知道任何其他支持这种情况的XML库)。 It only supports serializing to XML in push mode, ie by writing to an OutputStream or Writer. 它仅支持在推送模式下序列化为XML,即通过写入OutputStream或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). 您可以在单独的线程中进行序列化,并使用PipedOutputStream / PipedInputStream(类似于Activation为DataHource支持的DataHandler的DataHandler#getInputStream()所做的操作)。 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. 这将满足恒定的内存要求,但我想在您的情况下使用单独的线程导致的开销是不可接受的。

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. 请打开Axiom功能请求,以便我们可以在下一个版本中实现它。 I think it would be an interesting addition to Axiom. 我认为这对Axiom来说是一个有趣的补充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM