From d34746e0494c293403ef1c7ba15f03947b878c5e Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Mon, 1 Oct 2012 13:10:15 +0200 Subject: Use XmlStreamReader in TypeGetter, closes #23 --- src/de/danoeh/antennapod/syndication/handler/FeedHandler.java | 5 +---- src/de/danoeh/antennapod/syndication/handler/TypeGetter.java | 8 ++++++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3