Hi,
Can someone help me here please? I've written the following piece of code
using the NNTP classes to download an article from an NNTP server and save
it to disk. This works fine for text based articles but binary base
articles, UUENC, YEnc etc are getting mangled. I suspect it's something to
do with either a char-byte conversion or an encoding scheme somewhere but I
can't figure out where.
If someone has the time to take a look at this I'd really appreciate it.
public void getArticle(String article) {
Reader r = null;
BufferedReader rr = null;
ArticlePointer ap = new ArticlePointer();
boolean rc;
System.out.println("\t\t<" + "Requesting article: " + article);
try {
if (nntpThread.selectArticle("<" + article + ">", ap) == false) {
System.out.println(
"!Could not select article:" + nntpThread.getReplyString());
} else {
r = nntpThread.retrieveArticleBody("<" + article + ">");
System.out.println("\t\t>" + nntpThread.getReplyString());
if (r != null) {
rr = new BufferedReader(r);
while (rr.ready() == false) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} // wait for the newsserver to reply
String fname = "cache\\" + article + ".article";
File f = new File(fname);
FileWriter out =
new FileWriter(fname);
FileOutputStream fos = new FileOutputStream(f);
// I tried no encoding scehem, ASCII and UTF8 and none work.
OutputStreamWriter out2 = new OutputStreamWriter(fos,"UTF-8");
while (r.ready()) {
//out.write(rr.readLine()+"\n");
out2.write(r.read());
}
out.flush();
out.close();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
I have to cringe a little when I send this because I'm fairly new to Java
and I can hear the chuckles going on in my head now as you guys read the
above... any pointers are also gladly appreciated.
Thanks,
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]