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);
  }
}

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 ) ; } }
passes this outputstream to the closure , ensuring that the stream is closed after the closure returns , regardless of errors .
