简体   繁体   English

大量文本的数据类型?

[英]Data type for large amounts of text?

I'm developing a Java package that makes basic HTTP requests (GET, POST, PUT, and DELETE). 我正在开发一个用于发出基本HTTP请求(GET,POST,PUT和DELETE)的Java包。 Right now, I'm having it just print the output of the request. 现在,我只是打印请求的输出。 I would like to store it in a field, but I'm not sure if String supports large amounts of text. 我想将它存储在一个字段中,但我不确定String是否支持大量文本。 Is there a data type for large amounts of text, or is there a reasonable alternative to it? 是否存在大量文本的数据类型,或者是否有合理的替代方案? Right now, because I'm just printing it, I can't do anything with the data that is returned (like parse it, if it's JSON). 现在,因为我只是打印它,我不能对返回的数据做任何事情(比如解析它,如果它是JSON)。

Any ideas would be helpful. 任何想法都会有所帮助。

Edit: The code is online on GitHub . 编辑:代码在GitHub上在线。

Strings can take up to 2^31 - 1 characters so I suspect are big enough. 字符串最多可占用2 ^ 31 - 1个字符,因此我怀疑它们足够大。 Data from SO question 来自SO问题的数据

I see that you use BufferedReader in your code. 我看到你在代码中使用了BufferedReader You can just leave the string in there and pass that reader to your JSON parser for instance. 您可以将字符串保留在那里并将该阅读器传递给您的JSON解析器。 Would be more efficient than first creating a String out of it. 比首先创建一个字符串更有效。

If you are performing a single set of operations on the data, you can stream it through a pipeline and not even store the entire data in memory at any time. 如果要对数据执行一组操作,则可以通过管道对其进行流式处理,甚至不会将整个数据存储在内存中。 It can also boost performance as work can begin upon the first character rather than after the last is received. 它还可以提高性能,因为工作可以从第一个字符开始,而不是在收到最后一个字符之后。 Check out CharSequence. 查看CharSequence。

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

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