import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
}
protected String fetchURL(URL url) throws Exception {
+ return fetchURL(url, Charset.defaultCharset().name());
+ }
+
+ protected String fetchURL(URL url, String charset) throws Exception {
StringBuffer buf = new StringBuffer();
boolean done = false;
for (int count = 0; !done; count++) {
Thread.sleep(config.niceMilliseconds*(1<<count));
try {
BufferedReader reader = new BufferedReader(
- new InputStreamReader(url.openStream()));
+ new InputStreamReader(url.openStream(), charset));
String s;
while ((s = reader.readLine()) != null)
buf.append(s);
return buf.toString();
}
- protected JSONObject fetchJSON(URL url) throws Exception {
- String json = fetchURL(url);
+ protected JSONObject fetchJSON(URL url, String charset) throws Exception {
+ String json = fetchURL(url, charset);
logger.debug(json);
return JSONObject.fromObject(json);
}
+ protected JSONObject fetchJSON(URL url) throws Exception {
+ return fetchJSON(url, Charset.defaultCharset().name());
+ }
+
public void clearCache() {
cache.clear(getName());
}
The full license text can be found in the LICENSE file.
*/
-import java.io.BufferedReader;
import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamWriter;
-import org.apache.commons.lang.StringEscapeUtils;
-import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
}
JSONObject channels;
try {
- channels = fetchJSON(url);
+ channels = fetchJSON(url, "UTF8");
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
for (Channel c : channels) {
URL url = programmeUrl(c, day);
logger.debug("Programme url:" + url);
- JSONObject jsonObject = fetchJSON(url);
+ JSONObject jsonObject = fetchJSON(url, "UTF-8");
logger.debug(jsonObject.toString());
JSONArray listings = jsonObject.getJSONArray("listings");
for (int i = 0; i < listings.size(); i++) {
* @param args
*/
public static void main(String[] args) {
+ Logger.getRootLogger().setLevel(Level.TRACE);
Config config = Config.getDefaultConfig();
Horizon horizon = new Horizon(config);
horizon.clearCache();