开发者

Java limit at json format

I want to transfer some database data through a TCP socket. The data is formatted to JSON.

Since the database size might grow, I'm afraid that the String object maximum size will not be enough to store the entire data with JSON formatting.

I already had an problem transferring the data using the DataOutput function writeUTF().

What should I do? Maybe convert the database rows to CSV and transfer it through the Internet line by line? Or do I not need to worry about String limits and solve the writeUTF() probl开发者_运维百科em by getting the bytes of the String, transferring them through the socket and rebuilding the String from the bytes at the destination?


Java strings can be extremely long - you're unlikely to run into problems with the String type itself. If you convert the string to binary first, then use writeInt to write the number of bytes, then the bytes themselves, that should be fine. The problem with writeUTF is that it uses writeShort, so it only handles up to 64K of data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜