views:

34

answers:

1

I am trying to process RSS feed using Google Reader API, but the issue is that even if feed encoding is UTF-8 it is returned in an unreadable format.

resp.contentType = "text/xml"
resp.characterEncoding = "UTF-8"

URL url = new URL("http://www.google.com/reader/public/atom/feed/" + rss);
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), Charset.forName("UTF-8")));
String line;
StringBuilder content = new StringBuilder();
while ((line = reader.readLine()) != null) {
    content.append(line + "\n");
}
reader.close();
def feed = new XmlParser().parseText(content.toString())
 ...
new XmlNodePrinter(resp.writer).print(feed)

Is there are any additional encoding settings that I miss? The code runs on Google App Engine.

A: 

What happens if you do with more idiomatic Groovy? I think all of your code can be replaced by:

def feed = new URL( "http://www.google.com/reader/public/atom/feed/$rss" ).withReader( 'UTF-8' ) { r ->
  new XmlParser().parse( r )
}

...

new XmlNodePrinter( resp.writer ).print( feed )
tim_yates
Excellent, I do not know why but now it's ok. What could be the reason?
Vitaliy
Not sure... There might have been something up with the stream->reader charset chain. Looks ok though, just a little long winded ;-)
tim_yates