public void downloadStreamCall ( ResponseDownloadResource resource , HttpServletResponse response ) { final WrittenStreamCall streamCall = resource . getStreamCall ( ) ; if ( streamCall == null ) { String msg = "Either byte data or input stream is required: " + resource ; throw new IllegalArgumentException ( msg ) ; } try { final Integer contentLength = resource . getContentLength ( ) ; if ( contentLength != null ) { response . setContentLength ( contentLength ) ; } final OutputStream out = response . getOutputStream ( ) ; try { streamCall . callback ( createWrittenStreamOut ( out ) ) ; flushDownloadStream ( out ) ; } finally { closeDownloadStream ( out ) ; } } catch ( RuntimeException e ) { throw new ResponseDownloadFailureException ( "Failed to download the input stream: " + resource , e ) ; } catch ( IOException e ) { handleDownloadIOException ( resource , e ) ; } }
switched to stream call way for closing headache