开发者

HttpServletRequest InputStream corrupted?

I'm receiving a SOAPMessage over a java servlet with an attachmentpart containing a multipart mime. Doing this:

 InputStream inputStream = request.getInputStream();           
 byte[] data = IOUtils.toByteArray(inputStream);

 File file = new File("/usr/local/user/message.txt");
 FileOutputStream fos = new FileOutputStream(file);
 fos.write(data);
 fos.close();

Gives me corrupted data for the binary code in the multipart mime. Anyone knows why this is happening? I copied the binary data to a file and changed the file extension to the appropriate image extension but I'm getting a corrupted image. Comparing hexadecimal data of message.txt and a .snoop file shows that there are slight differences in the hexadecimal data causing the distortion开发者_如何学C. There were no changes in the ASCII data. Thanks.

There is distortion, as in you can see the picture looks correct at the start, but it starts looking weird after a while because the hexadecimal values are wrong. For example: 06 04 04 04 04 04 06 04 04 06 0a from the client becomes 06 04 04 04 04 04 06 04 04 06 0D after I do the above.


Based on the comments, it appears that the file is being written to disk correctly (that is my interpretation).

WinSCP is used to transfer the file from the (Linux/Unix) machine to a Windows machine. The mode of transfer employed in the transfer process could result in WinSCP converting all unix-style line endings to Windows-style line endings, or vice-versa depending on where the transfer originated from. This occurs when text mode is employed to transfer the file, or when WinSCP is allowed to determine whether it should use the text or binary mode to transfer the file. You might have set it to the default mode, so force the file to be transferred in binary; if this hasn't worked, you'll need to investigate further.

If WinSCP appears to be the cause of this problem, you could confirm it, by viewing the binary contents of the files on both platforms. You could use xxd on Linux/Unix. On Windows, one of the utilities listed in this question will help.

You may also use any other file copy protocols like FTP, SFTP or even use NFS or Samba to transfer the files, and establish WinSCP to be the cause.


For multipart MIME you can use Apache Fileupload library. you can find it here :

Apache Fileupload download path

Starter tutorial

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜