Hafas: Handle unparsable XML when querying for departures.

This commit is contained in:
Andreas Schildbach 2015-08-26 18:04:16 +02:00
parent 1ae48117ba
commit 5048e826dc

View file

@ -505,11 +505,14 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final String normalizedStationId = normalizeStationId(stationId); final String normalizedStationId = normalizeStationId(stationId);
StringReplaceReader reader = null; StringReplaceReader reader = null;
String firstChars = null;
try try
{ {
// work around unparsable XML // work around unparsable XML
reader = new StringReplaceReader(new InputStreamReader(httpClient.getInputStream(uri), Charsets.ISO_8859_1), " & ", " & "); final InputStream is = httpClient.getInputStream(uri);
firstChars = HttpClient.peekFirstChars(is);
reader = new StringReplaceReader(new InputStreamReader(is, Charsets.ISO_8859_1), " & ", " & ");
reader.replace("<b>", " "); reader.replace("<b>", " ");
reader.replace("</b>", " "); reader.replace("</b>", " ");
reader.replace("<u>", " "); reader.replace("<u>", " ");
@ -741,7 +744,7 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
} }
catch (final XmlPullParserException x) catch (final XmlPullParserException x)
{ {
throw new RuntimeException(x); throw new ParserException("cannot parse xml: " + firstChars, x);
} }
finally finally
{ {