From d34746e0494c293403ef1c7ba15f03947b878c5e Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 1 Oct 2012 13:10:15 +0200 Subject: [PATCH] Use XmlStreamReader in TypeGetter, closes #23 --- .../antennapod/syndication/handler/FeedHandler.java | 5 +---- .../danoeh/antennapod/syndication/handler/TypeGetter.java | 8 ++++++-- tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/de/danoeh/antennapod/syndication/handler/FeedHandler.java b/src/de/danoeh/antennapod/syndication/handler/FeedHandler.java index 050daf862..9b25d16c4 100644 --- a/src/de/danoeh/antennapod/syndication/handler/FeedHandler.java +++ b/src/de/danoeh/antennapod/syndication/handler/FeedHandler.java @@ -1,9 +1,7 @@ package de.danoeh.antennapod.syndication.handler; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.io.Reader; import javax.xml.parsers.ParserConfigurationException; @@ -28,12 +26,11 @@ public class FeedHandler { factory.setNamespaceAware(true); SAXParser saxParser = factory.newSAXParser(); File file = new File(feed.getFile_url()); - InputStream inputStream = new FileInputStream(file); Reader inputStreamReader = new XmlStreamReader(file); InputSource inputSource = new InputSource(inputStreamReader); saxParser.parse(inputSource, handler); - inputStream.close(); + inputStreamReader.close(); return handler.state.feed; } } diff --git a/src/de/danoeh/antennapod/syndication/handler/TypeGetter.java b/src/de/danoeh/antennapod/syndication/handler/TypeGetter.java index 04c8cdd42..d4c61119f 100644 --- a/src/de/danoeh/antennapod/syndication/handler/TypeGetter.java +++ b/src/de/danoeh/antennapod/syndication/handler/TypeGetter.java @@ -6,6 +6,7 @@ import java.io.FileReader; import java.io.IOException; import java.io.Reader; +import org.apache.commons.io.input.XmlStreamReader; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; @@ -72,12 +73,15 @@ public class TypeGetter { } private Reader createReader(Feed feed) { - FileReader reader; + Reader reader; try { - reader = new FileReader(new File(feed.getFile_url())); + reader = new XmlStreamReader(new File(feed.getFile_url())); } catch (FileNotFoundException e) { e.printStackTrace(); return null; + } catch (IOException e) { + e.printStackTrace(); + return null; } return reader; } diff --git a/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java b/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java index 9bebbc173..94dfaa436 100644 --- a/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java +++ b/tests/src/de/danoeh/antennapod/test/FeedHandlerTest.java @@ -24,6 +24,7 @@ public class FeedHandlerTest extends AndroidTestCase { private static final String FEEDS_DIR = "testfeeds"; private static final String[] urls = { + "http://podcast.homerj.de/podcasts.xml", "http://www.dradio.de/rss/podcast/sendungen/wissenschaftundbildung/", "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundverbraucher/", "http://www.dradio.de/rss/podcast/sendungen/literatur/",