public static void copyStream(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[8192];

    try (InputStream is = in; OutputStream os = out) {
      int read = is.read(buffer);
      while (read > 0) {
        os.write(buffer, 0, read);
        read = is.read(buffer);
      }
    }
  }
Returns the text read from the given stream as a String.
Closes the given stream upon return.
spock-core/src/main/java/org/spockframework/util/IoUtil.java