title: ClientAbortException: java.io.IOException: Broken pipe
body: <p>I have the following code to send a jpg image on the outputstream in Grails. I use this block inside a cache headers generate{...} statement. </p>
  
  <pre><code>                            def imageByteArray = // some image byte []
              response.setContentType("image/jpeg")
              response.setHeader("Content-disposition", "filename=\"${imageName}${imageExtension}\"")
              response.setContentLength(imageByteArray.size())
  
              def outputStream = null
              try {
                  outputStream = response.outputStream
                  outputStream &lt;&lt; imageByteArray
              } catch (IOException e){
                  log.error('getImage() - Canceled download?', e)
              } finally {
                  if (outputStream != null){
                      try {
                          outputStream.close()
                      } catch (IOException e) {
                          log.error('Exception on close', e)
                      }
                  }
                  return
              }
  </code></pre>
  
  <p>I get the following error: </p>
  
  <pre><code>2013-09-17 12:51:55,033 [http-nio-80-exec-15] ERROR test.ItemController  - getImage() - Canceled download?
  ClientAbortException:  java.io.IOException: Broken pipe
      at test.ItemController$_getImage_closure2_closure11.doCall(ItemController.groovy:287)
      at com.grailsrocks.cacheheaders.CacheHeadersService.callClosure(CacheHeadersService.groovy:209)
      at com.grailsrocks.cacheheaders.CacheHeadersService.withCacheHeaders(CacheHeadersService.groovy:201)
      at CacheHeadersGrailsPlugin$_addCacheMethods_closure7_closure11.doCall(CacheHeadersGrailsPlugin.groovy:61)
      at test.ItemController.getImage(ItemController.groovy:204)
      at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
      at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
      at test.ItemController.getFacebookImage(ItemController.groovy:98)
      at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
      at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:724)
  </code></pre>
  
  <p>I could not figure out what to change in order to avoid this error. I also tried to use flush() on the outputstream but it did not work. 
  What to do?</p>
  
  <p>From the error log I can see that  "Canceled download?" is thrown thus I suppose that something went wrong on the write operation? </p>