public final void writeStream ( InputStream stream , OnStreamWriteListener listener ) throws IOException { if ( listener == null ) throw new IllegalArgumentException ( "listener MUST not be null!" ) ; byte [ ] buffer = new byte [ UploadService . BUFFER_SIZE ] ; int bytesRead ; try { while ( listener . shouldContinueWriting ( ) && ( bytesRead = stream . read ( buffer , 0 , buffer . length ) ) > 0 ) { write ( buffer , bytesRead ) ; flush ( ) ; listener . onBytesWritten ( bytesRead ) ; } } finally { stream . close ( ) ; } }
Writes an input stream to the request body . The stream will be automatically closed after successful write or if an exception is thrown .