0

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

Ryan
  • 1
  • You really should check all your nntpreader.read() calls. You're reading from a socket, you are not guaranteed to read the no. of bytes you've set as the buffer size. – nos Feb 20 '10 at 17:41
  • why not use the [GNU](http://www.gnu.org/software/classpathx/javamail/) library? Or, at least fork it if you don't like it :) – Thufir May 05 '12 at 08:47

1 Answers1

1

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
  • 342,105
  • 78
  • 482
  • 720