SOAP - 非常大的 XML 响应 - OutOfMemoryError [英] SOAP - Very large XML response - OutOfMemoryError

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

问题描述

首先,这个问题看起来像 非常大的 SOAP 响应 - Android- 内存不足错误 subject.由于本人英文能力差,与此题相似,为了便于理解,抄录了部分陈述段落.

我有一个应用程序,我需要通过对 Web 服务的 SOAP 调用下载大量数据.然后将响应发送到显示 XML 文件的函数.

I have an application where i need to download a large amount of data via a SOAP call to a webservice. The response is then sent to a function which display the XML file.

数据大小超过 11MB,我每次都会出现 java.lang.OutOfMemoryError.

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

修改网络服务以提供更少量的数据不是一种选择.

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

我使用Http请求"来获取数据.我知道:我的请求很好,soapUi 和wireshark 返回预期的响应.

I use "Http request" to get datas. I know that : my resquest is fine, soapUi and wireshark return expected responses.

但我的 AVD 无法通过此行

But my AVD isn't able to pass this line

HttpResponse httpResponse = httpClient.execute(httpPost);

经过几分钟的工作(在此期间,wireshark 恢复了一些预期的查询)出现此错误

After some minutes of work (during which wireshark recovers some expected queries) this error is made

 Out of memory on a 16705124-byte allocation.

我尝试将 SD 卡大小升级到 20GB,但仍然出错.

I tried to upgrade the SD card size to 20GB, yet, error still.

解析httpResponse大概是下一步了,有没有可能在HttpResponse接收数据的时候通过将它分成几部分来解析?

Parsing httpResponse is probably the next step, is it possible to parse HttpResponse while it receives data by fragmenting it into several parts by exmple?

你有什么想法吗?

谢谢,桑德雷

推荐答案

感谢 Graeme,以字节流的方式打开连接.如果对某人有帮助,这是我的源代码

Thank's Graeme, opening connection as a byte stream works. If it could be helpfull to somebody, this is my source code

        //Make a temporary file to save data
        File responseFile = File.createTempFile("SOAP", "xml", context.getFilesDir());      
        int nbCharRead = 0; int i=0; int totalRead = 0;

        //Send query
        OutputStream outputS = url_Connection.getOutputStream();
        Writer w_out = new OutputStreamWriter(outputS);
        w_out.write(webServiceXml);
        w_out.flush();
        w_out.close();


        //Buffers
        BufferedReader bufReader = new BufferedReader(new InputStreamReader(url_Connection.getInputStream()));
        BufferedWriter bufWriter = new BufferedWriter(new FileWriter(responseFile));
        char[] buffer = new char[10000];



        while((nbCharRead = bufReader.read(buffer, 0, 10000)) != -1)
        {
            totalRead += nbCharRead;
            Log.d("Test InputStream", "i: " + i++ +" - " + nbCharRead + " -> " + totalRead);
            bufWriter.write(buffer, 0, nbCharRead );
        }       

        if(bufWriter != null)
        {
            bufWriter.flush();
            bufWriter.close();
        }


        Log.w(MsgLog, "--- Stream Got--- ; Total : " + totalRead);

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

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