From dec029667a3a56ab52f03e62ab16d51647b7c1f1 Mon Sep 17 00:00:00 2001 From: Joris van Winden Date: Sat, 13 Dec 2014 17:05:49 +0100 Subject: [PATCH] Add RSSStringDumpParser class, for issue #17. --- .../mcsoxford/rss/RSSStringDumpParser.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/org/mcsoxford/rss/RSSStringDumpParser.java diff --git a/src/main/java/org/mcsoxford/rss/RSSStringDumpParser.java b/src/main/java/org/mcsoxford/rss/RSSStringDumpParser.java new file mode 100644 index 0000000..bafad9d --- /dev/null +++ b/src/main/java/org/mcsoxford/rss/RSSStringDumpParser.java @@ -0,0 +1,44 @@ +package org.mcsoxford.rss; + +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.IOException; + +/* + * RSS feed to string parser. + * + * @author Joris van Winden + */ + +public class RSSStringDumpParser { + + public RSSStringDumpParser() {} + + /* + * Parses input stream as a string. It is the responsibility of the caller to + * close the stream. + * + * @param feed RSS 2.0 feed input stream + * @return string representation of the feed + * @throws RSSFault when io goes wrong + */ + public String parse(InputStream feed) { + + BufferedReader reader = new BufferedReader(new InputStreamReader(feed)); + + StringBuilder result = new StringBuilder(); + + String line; + + try { + while((line = reader.readLine()) != null) { + result.append(line); + } + } catch (IOException e) { + throw new RSSFault(e); + } + + return result.toString(); + } +}