X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=tests%2Forg%2Fcacert%2Fgigi%2FtestUtils%2FIOUtils.java;h=23db401f8221d0c50769c08acb893437e53ba7a3;hb=265b98aed618c4b153f9c96580fb619ab7ce70ec;hp=e33192e7d1fb893e228b40fad3372cc1c14ac45b;hpb=943d8e7ed0ea5a9d56e7e694a3cbd849c52bad16;p=gigi.git diff --git a/tests/org/cacert/gigi/testUtils/IOUtils.java b/tests/org/cacert/gigi/testUtils/IOUtils.java index e33192e7..23db401f 100644 --- a/tests/org/cacert/gigi/testUtils/IOUtils.java +++ b/tests/org/cacert/gigi/testUtils/IOUtils.java @@ -1,7 +1,9 @@ package org.cacert.gigi.testUtils; +import java.io.ByteArrayOutputStream; import java.io.CharArrayWriter; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.HttpURLConnection; @@ -15,7 +17,7 @@ public class IOUtils { public static String readURL(URLConnection in) { try { - if ( !in.getContentType().equals("text/html; charset=UTF-8")) { + if ( !in.getContentType().equals("text/html; charset=UTF-8") && !in.getContentType().equals("text/plain; charset=UTF-8")) { if (in instanceof HttpURLConnection && ((HttpURLConnection) in).getResponseCode() != 200) { System.err.println(readURL(new InputStreamReader(((HttpURLConnection) in).getErrorStream(), "UTF-8"))); } @@ -36,10 +38,26 @@ public class IOUtils { while ((len = in.read(buffer)) > 0) { caw.write(buffer, 0, len); } + in.close(); return new String(caw.toCharArray()); } catch (IOException e) { throw new Error(e); } } + + public static byte[] readURL(InputStream in) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] buffer = new byte[1024]; + int len = 0; + try { + while ((len = in.read(buffer)) > 0) { + baos.write(buffer, 0, len); + } + in.close(); + return baos.toByteArray(); + } catch (IOException e) { + throw new Error(e); + } + } }