开发者

Sending big String over BufferedWriter

is there some problem sending a big String (5开发者_StackOverflow社区Mb, one xml file, all i one line) with a BufferedWriter?

It works very fast. Is there some golden rule disallowing lines longer than a few K? Then I would have to write some extra filetransfer protocol... :-(


The BufferedWriter itself won't determine how quickly things go. It's just going to do some buffering for you. It really depends on what you're then writing to... on a LAN, 5MB isn't particularly huge, but over a mobile connection it would take a long time.

In other words: it depends. There's no "golden rule" disallowing long lines... but then we don't know what protocol you're using. It's possible that in your particular protocol there is a size limit. If you want a more detailed answer, you'll have to add more detail to your question...


If it works, then it works. If it doesn't work, break the string into chunks.


Is this 5Mb line the only thing you're writing? If so then a BufferedWriter isn't adding anything over the Writer it wraps. A BufferedWriter is useful if you're doing lots of small writes and want to buffer them up into larger chunks to send to the underlying Writer, which may have an overhead on it's write() method (for example disk seek time/rotation delay).


What might be a little problem is the receiving side - does this accept such long lines? Some programs might be prepared to receive long lines, but are optimized for the common case of short lines, thus using long lines would slow them down.

Also, what exactly consists a line is system dependent, too - most often it means that there comes a \n after it (Unix), or a \r\n (DOS/Windows/most public Internet protocols).

Also, take note that lines written and calls to the BufferedWriter write methods are two orthogonal things - you can make multiple calls to write writing only one line at all, or you can write multiple lines with only one write call.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜