NNTP 客户端 - Java - 下载文章随机下载 3 个额外的垃圾字节
我编写了这个 NNTP 客户端...并且我尝试将其用作更大项目的一部分,但似乎 downloadArticle(string msgID) 正在下载一些额外的字节,但是是随机的。例如,有一次我将运行该应用程序,它会在 CR/LF 之后插入 3 个垃圾字节。我将再次运行该应用程序,它不会下载这些字节。我已经隔离了这个问题,它不在 YNC 解码器等中......它肯定在这个 NNTPclient 类中。
为了完整起见,我发布了整个课程。代码在这里: http://www.pastebin.com/m214131cc
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于换行符,您有很多复杂且因此容易出错的逻辑 - 几乎可以肯定错误就在其中的某个地方。您似乎还使用了 In/OutputStreams 和 Readers/Writers 的不一致(且命名不一致的组合)。
问题是:您实际上需要所有这些吗?我很确定您不需要该类似乎所做的就是将 InputStream 的内容写入文件,为此,您不需要考虑换行符(或者实际上是字符) - 只需通过
字节传输原始字节。 []
缓冲区(或者简单地使用 Apache commons-io 的 IOUtils class)。或者如果您需要规范换行符,请使用 BufferedReader.readLine() 而不是编写自己的、容易出错的换行符识别逻辑。
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.