/**
* ChannelList.readFromStream is called by both MirrorUpdater and
* TvBrowserDataService. The MirrorUpdater calls this method without
* DataService and doesn't need the IconLoader
*/
IconLoader iconLoader = null;
if (dataService != null && dataService instanceof TvBrowserDataService) {
File dataDir = ((TvBrowserDataService) dataService).getWorkingDirectory();
iconLoader = new IconLoader(TvBrowserDataService.getInstance(), mGroup.getId(), dataDir);
}
String[] tokens;
while ((tokens = reader.readNext()) != null) {
if (tokens.length < 4) {
throw new FileFormatException("Syntax error in mirror file line " + lineCount + ": column count is '" + tokens.length + " < 4' : " + tokens[0]);
}
String country = null, timezone = null, id = null, name = null, copyright = null, webpage = null, iconUrl = null, categoryStr = null, unescapedname = null;
try {
country = tokens[0];
timezone = tokens[1];
id = tokens[2];
name = tokens[3];
copyright = tokens[4];
webpage = tokens[5];
iconUrl = tokens[6];
categoryStr = tokens[7];
if (tokens.length > 8) {
unescapedname = name;
name = StringEscapeUtils.unescapeHtml(tokens[8]);
}
} catch (ArrayIndexOutOfBoundsException e) {
// ignore
}
int categories = Channel.CATEGORY_NONE;
if (categoryStr != null) {
try {
categories = Integer.parseInt(categoryStr);
} catch (NumberFormatException e) {
categories = Channel.CATEGORY_NONE;
}
}
Channel channel = new Channel(dataService, name, id, TimeZone.getTimeZone(timezone), country, copyright,
webpage, mGroup, null, categories, unescapedname);
if (iconLoader != null && iconUrl != null && iconUrl.length() > 0) {
Icon icon = iconLoader.getIcon(id, iconUrl);
if (icon != null) {
channel.setDefaultIcon(icon);
}
}
addChannel(channel, iconUrl);
lineCount++;
}
reader.close();
if (iconLoader != null) {
iconLoader.close();
}
}