序列化字节被添加到servlet响应输出流中,如何避免它?

时间:2017-06-10 10:47:30

标签: java servlets serialization deserialization outputstream

在doPost中,返回位图

        String mimeType = sc.getMimeType(filename);
        // Set content type
        resp.setContentType(mimeType);
        // Set content size
        File file = new File(filename);
        resp.setContentLength((int)file.length());

        // Open the file and output streams
        FileInputStream in = new FileInputStream(file);
        // Copy the contents of the file to the output stream
        byte[] buf = new byte[1024];
        int count = 0;
        while ((count = in.read(buf)) >= 0) {
            outStream.write(buf, 0, count);
        }

用fiddler测试,在标题中添加4个额外字节,从bmp中删除4个字节。它们是AC ED 00 05,它来自序列化算法。它导致bmp无法识别。

创建输出流时如何避免这些序列化字节?

0 个答案:

没有答案