ClientAbortException:java.io.IOException:管道损坏

时间:2013-09-17 11:25:44

标签: java grails spring-mvc grails-2.0

我有以下代码在Grails的输出流上发送jpg图像。我在缓存头文件生成{...}语句中使用此块。

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

我收到以下错误:

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)

我无法弄清楚要改变什么以避免此错误。我也尝试在输出流上使用flush()但它没有用。 怎么办?

从错误日志中我可以看到&#34;取消下载?&#34;抛出因此我认为写操作出了什么问题?

0 个答案:

没有答案