非常大的SOAP响应 - Android-内存不足的错误 [英] Very large SOAP response - Android- out of memory error

查看:122
本文介绍了非常大的SOAP响应 - Android-内存不足的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我需要通过SOAP调用下载大量的数据到一个web服务到应用程序时,它是第一次运行。该响应然后被发送到一个函数,它的数据转换的XML和存储在一个数据库文件

I have an application where i need to download a large amount of data via a SOAP call to a webservice into the application when it is first run. The response is then sent to a function which converts the XML and stores the data in a db file.

数据超过16MB大小,我有一个java.lang.OutOfMemoryError每次。

The data is more than 16MB in size and i have a java.lang.OutOfMemoryError everytime.

修改web服务给予了少量的数据是不是一种选择。

Modifying the webservice to give out smaller amounts of data is not an option.

有没有一种方法能够下载大量数据?像一个InputStream吧?

Is there a way to be able to download the large data? Something like an InputStream perhaps?

这是我的code

public Protocol[] getProtocols() {

    String METHOD_NAME = "GetProtocols";
    String SOAP_ACTION = "urn:protocolpedia#GetProtocols";
    Log.d("service", "getProtocols");
    SoapObject response = invokeMethod(METHOD_NAME, SOAP_ACTION);
    return retrieveProtocolsFromSoap(response);
}

private SoapObject invokeMethod(String methodName, String soapAction) {
    Log.d(TAG, "invokeMethod");
    SoapObject request = GetSoapObject(methodName);
    SoapSerializationEnvelope envelope = getEnvelope(request);
    return makeCall(envelope, methodName, soapAction);

}

任何人都可以建议我应该在这种情况下做呢?

Can anyone suggest what should be done in this case?

感谢和问候 穆库尔

推荐答案

两种策略来帮你解决这个问题:

Two strategies to help you solve this problem:

  1. 直接保存您的SOAP XML流盘,你下载它。不要将其存储在内存中。
  2. 使用SAX风格的解析器,你不加载在内存中的整个DOM,而是解析它在块解析它。

根据不同的类型的XML,你正在处理的,使用SAX解析器通常很难在code;你将不得不跟踪自己很多东西,你将无法从节跳到你的DOM树的部分。但内存消耗将降低的方式。​​

Depending on the kind of XML you are handling, using SAX parsers is usually harder in code; you will have to keep track of many things yourself, and you won't be able to "jump" from section to section of your DOM tree. But the memory consumption will be way lower.

请注意,然而,许多高层次的网络通信库通常加载整个XML DOM在内存中,这可能是这里的情况。你可能会需要创建和管理的HTTP连接自己,然后手动解析的结果。

Take note, however, that many "high-level" network communication libraries usually load the whole XML DOM in memory, which might be the case here. You will probably have to create and manage the HTTP connection yourself, and then manually parse the result.

这篇关于非常大的SOAP响应 - Android-内存不足的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆