X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FIOUtils.java;h=e33192e7d1fb893e228b40fad3372cc1c14ac45b;hb=943d8e7ed0ea5a9d56e7e694a3cbd849c52bad16;hp=2db46f87832bb8acfeb2d90fb571b6cb22ec6cab;hpb=2233a655b4ef4c1122a406e83a0e6334b9fd49b6;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/IOUtils.java b/tests/org/cacert/gigi/testUtils/IOUtils.java index 2db46f87..e33192e7 100644 --- a/tests/org/cacert/gigi/testUtils/IOUtils.java +++ b/tests/org/cacert/gigi/testUtils/IOUtils.java @@ -8,38 +8,38 @@ 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")) { - 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) { - throw new Error(e); - } - - } - - public static String readURL(Reader in) { - CharArrayWriter caw = new CharArrayWriter(); - char[] buffer = new char[1024]; - int len = 0; - try { - while ((len = in.read(buffer)) > 0) { - caw.write(buffer, 0, len); - } - return new String(caw.toCharArray()); - } catch (IOException e) { - throw new Error(e); - } - - } + + private IOUtils() { + + } + + public static String readURL(URLConnection in) { + try { + if ( !in.getContentType().equals("text/html; charset=UTF-8")) { + 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) { + throw new Error(e); + } + + } + + public static String readURL(Reader in) { + CharArrayWriter caw = new CharArrayWriter(); + char[] buffer = new char[1024]; + int len = 0; + try { + while ((len = in.read(buffer)) > 0) { + caw.write(buffer, 0, len); + } + return new String(caw.toCharArray()); + } catch (IOException e) { + throw new Error(e); + } + + } }