I have a program that I'm writing where I am using another company's library to download some reports from their website. I want to parse these reports before I write them to a file, because if they match certain criteria, I want to disregard them.
Problem is, their method, called download() returns a java.io.Reader. The only method available to me is
int read(char[] cbuf);
Printing this returned array out gives me meaningless characters. I want to be able to identify what character set I'm working with or convert it to a byte array but I can't figure out how to do it. I've tried
//retrievedFile is my Reader object
char[] cbuf = new char[2048];
int numChars = retrievedFile.read(cbuf);
//I've tried other character sets, too
new String(cbuf).getBytes("UTF-8");
and I'm afraid to downcast to a more useful reader because I can't know for sure if it will work or not. Any suggestions?
EDIT
When I say it prints out "meaningless characters", I don't mean that it looks like the example given by Jon Skeet. It's really hard to describe because I'm not at my machine right now, but I think it's an encoding issue. The characters seem to have indentations and structure similar to the look of the reports. I'll try these suggestions as soon as I get back on Tuesday (I'm only an intern, so I haven't bothered with setting up a remote account or anything).
BufferedReader
? There is no reason why it should not work... – GilliesSystem.out.print(cbuf[i])
gives you garbage for i=0, 1, 2.., then the other company's lib has a problem, or you did not configure it well. – Bilge