简体   繁体   English

大型流的IOUtils.toString()的替代方法?

[英]Alternative to IOUtils.toString() for large streams?

I'm getting a large response stream back from an HTTP request. 我收到了来自HTTP请求的大量响应流。 It's JSON, so I need to convert it to a string for processing. 它是JSON,因此我需要将其转换为字符串进行处理。 I'm running out of heap space on the call to toString. 我在调用toString时堆空间不足。

Code is as follows: 代码如下:

URLConnection conn = new URL(url + "?query=" + URLEncoder.encode(sparql, "UTF-8") + "&output=JSON").openConnection();
conn.setRequestProperty("Accept-Charset", "UTF-8");
InputStream respStream = conn.getInputStream();
response = IOUtils.toString(respStream, "UTF-8");
respStream.close();

I've tried setting the heap size as large as I can. 我尝试过设置尽可能大的堆大小。 I can't get the data in smaller chunks easily (but if there's not a better choice, I'll implement that). 我无法轻松地将数据分成小块(但是如果没有更好的选择,我将实现它)。 Any suggestions? 有什么建议么?

I wound up just requesting the data in smaller chunks, which I should have just done to begin with. 最后,我只是以较小的块请求数据,而这应该是我应该做的。 This was kind of a stupid question, thanks for taking the time to look at it. 这是一个愚蠢的问题,感谢您抽出宝贵的时间来研究它。

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

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