import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.net.HttpURLConnection;
import java.net.URLConnection;
public class IOUtils {
private IOUtils() {
}
+
public static String readURL(URLConnection in) {
try {
if (!in.getContentType().equals("text/html; charset=UTF-8")) {
- throw new Error("Unrecognized content-type: "
- + in.getContentType());
+ if (in instanceof HttpURLConnection && ((HttpURLConnection) in).getResponseCode() != 200) {
+ System.err
+ .println(readURL(new InputStreamReader(((HttpURLConnection) in).getErrorStream(), "UTF-8")));
+ }
+ throw new Error("Unrecognized content-type: " + in.getContentType());
}
return readURL(new InputStreamReader(in.getInputStream(), "UTF-8"));
} catch (IOException e) {
}
}
+
public static String readURL(Reader in) {
CharArrayWriter caw = new CharArrayWriter();
char[] buffer = new char[1024];