0

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.

4

1 回答 1

0

如果您使用更惯用的 Groovy 会发生什么?我认为您的所有代码都可以替换为:

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 )
于 2010-09-14T09:27:52.670 回答