为什么如此复杂,为什么要将完整图像读入内存?一个简单得多的解决方案:
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
enc.encode(new FileInputStream("/path/to/file.whatever"), response.getOutputStream());
}