code: public static <T, U extends OutputStream> T withStream(U os, @ClosureParams(value=FirstParam.class) Closure<T> closure) throws IOException {
          try {
              T result = closure.call(os);
              os.flush();
  
              OutputStream temp = os;
              os = null;
              temp.close();
  
              return result;
          } finally {
              closeWithWarning(os);
          }
      }
docs: Passes this OutputStream to the closure, ensuring that the stream
  is closed after the closure returns, regardless of errors.
  
  @param os      the stream which is used and then closed
  @param closure the closure that the stream is passed into
  @return the value returned by the closure
  @throws IOException if an IOException occurs.
  @since 1.5.2