开发者

NNTP client - Java - Download Article is downloaded 3 extra garbage bytes randomly [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_StackOverflow社区 Closed 9 years ago.

I wrote this NNTP client... and I am trying to use it as part of a bigger project, but it seems that the downloadArticle(string msgID) is downloading some extra bytes, but randomly. For example, one time I will run the application and it will insert 3 garbage bytes after a CR/LF. I will run the application again and it doesn't download those bytes. I have isolated the problem and it is not in the yenc decoder etc... it is definitely in this NNTPclient class.

I posted the whole class for completeness. Code is here: http://www.pastebin.com/m214131cc


You have a lot of complex and therefore error-prone logic concerning newlines- the error is almost certainly somewhere in there. You also seem to be using an inconsistent (and inconsistently-named mix of In/OutputStreams and Readers/Writers.

The question is: do you actually need all that? I'm pretty sure that you don't. All that that class seems to do is write the contents of an InputStream to a file. For that, you do not need to think about newlines (or, indeed, characters) - just transfer the raw bytes via a byte[] buffer (or simply use Apache commons-io's IOUtils class).

Or if you need to normalize newlines, use BufferedReader.readLine() instead of writing your own, error-prone newline recognition logic.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜