Commit 722f82a8 authored by 雍欢's avatar 雍欢

CommonController - 添加文件输出拦截器

parent d4c55cc3
...@@ -451,20 +451,16 @@ public class CommonController extends ControllerBase { ...@@ -451,20 +451,16 @@ public class CommonController extends ControllerBase {
res.setContentType(ContentTypeHelper.getContentType(type)); res.setContentType(ContentTypeHelper.getContentType(type));
res.setCharacterEncoding("utf-8"); res.setCharacterEncoding("utf-8");
res.setHeader("Content-Disposition", "inline;fileName=" + System.currentTimeMillis() + "." + type + ""); res.setHeader("Content-Disposition", "inline;fileName=" + System.currentTimeMillis() + "." + type + "");
InputStream is = null;
ServletOutputStream out = null; try (FileInputStream fis = new FileInputStream(file);
try { InputStream is = outputFileInterceptor != null
is = outputFileInterceptor != null ? outputFileInterceptor.intercept(fis, type, this)
? outputFileInterceptor.intercept(new FileInputStream(file), type, this) : fis;
: new FileInputStream(file); ServletOutputStream out = res.getOutputStream();
out = res.getOutputStream(); ) {
IOUtils.copy(is, out); IOUtils.copy(is, out);
res.flushBuffer(); } catch (Exception e) {
} catch (final Exception e) {
throw new ApplicationException(e); throw new ApplicationException(e);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(out);
} }
return null; return null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment