tags:

views:

123

answers:

1

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

A: 

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.

Michael Borgwardt