public void download ( OutputStream output , ProgressListener listener ) { URL url = CONTENT_URL_TEMPLATE . build ( this . getAPI ( ) . getBaseURL ( ) , this . fileID , this . getID ( ) ) ; BoxAPIRequest request = new BoxAPIRequest ( this . getAPI ( ) , url , "GET" ) ; BoxAPIResponse response = request . send ( ) ; InputStream input = response . getBody ( listener ) ; long totalRead = 0 ; byte [ ] buffer = new byte [ BUFFER_SIZE ] ; try { int n = input . read ( buffer ) ; totalRead += n ; while ( n != - 1 ) { output . write ( buffer , 0 , n ) ; n = input . read ( buffer ) ; totalRead += n ; } } catch ( IOException e ) { throw new BoxAPIException ( "Couldn't connect to the Box API due to a network error." , e ) ; } response . disconnect ( ) ; }
Downloads this version of the file to a given OutputStream while reporting the progress to a ProgressListener .