Use XmlStreamReader in TypeGetter, closes #23

This commit is contained in:
daniel oeh 2012-10-01 13:10:15 +02:00
parent 7ea73f01ae
commit d34746e049
3 changed files with 8 additions and 6 deletions

View File

@ -1,9 +1,7 @@
package de.danoeh.antennapod.syndication.handler; package de.danoeh.antennapod.syndication.handler;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@ -28,12 +26,11 @@ public class FeedHandler {
factory.setNamespaceAware(true); factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser(); SAXParser saxParser = factory.newSAXParser();
File file = new File(feed.getFile_url()); File file = new File(feed.getFile_url());
InputStream inputStream = new FileInputStream(file);
Reader inputStreamReader = new XmlStreamReader(file); Reader inputStreamReader = new XmlStreamReader(file);
InputSource inputSource = new InputSource(inputStreamReader); InputSource inputSource = new InputSource(inputStreamReader);
saxParser.parse(inputSource, handler); saxParser.parse(inputSource, handler);
inputStream.close(); inputStreamReader.close();
return handler.state.feed; return handler.state.feed;
} }
} }

View File

@ -6,6 +6,7 @@ import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import org.apache.commons.io.input.XmlStreamReader;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory; import org.xmlpull.v1.XmlPullParserFactory;
@ -72,12 +73,15 @@ public class TypeGetter {
} }
private Reader createReader(Feed feed) { private Reader createReader(Feed feed) {
FileReader reader; Reader reader;
try { try {
reader = new FileReader(new File(feed.getFile_url())); reader = new XmlStreamReader(new File(feed.getFile_url()));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} }
return reader; return reader;
} }

View File

@ -24,6 +24,7 @@ public class FeedHandlerTest extends AndroidTestCase {
private static final String FEEDS_DIR = "testfeeds"; private static final String FEEDS_DIR = "testfeeds";
private static final String[] urls = { 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/wissenschaftundbildung/",
"http://www.dradio.de/rss/podcast/sendungen/wirtschaftundverbraucher/", "http://www.dradio.de/rss/podcast/sendungen/wirtschaftundverbraucher/",
"http://www.dradio.de/rss/podcast/sendungen/literatur/", "http://www.dradio.de/rss/podcast/sendungen/literatur/",