连续调用 'SOAPMessage.writeTo' 抛出读取错误

Consecutive calls to 'SOAPMessage.writeTo' throw Read Error

我的应用程序中的 SOAP 消息包含从文件创建的附件。 当我多次调用 soapMessage.writeTo(System.out); 时,它抛出以下异常:

SEVERE: SAAJ0540: Error during saving a multipart message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
    at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1233)
    at main.SOAPMTOMUtilityTest.main(SOAPMTOMUtilityTest.java:102)
Caused by: java.io.IOException: Read error
    at java.io.FileInputStream.readBytes(Native Method)

这是一个错误吗?还是我做错了什么?

我找到原因了。 'MyDataSource' class 是 return 同一个输入流。每次接到调用时,预计 return 一个新的 InputStream。

public class MyDataSource implements DataSource {
    public InputStream getInputStream() throws IOException {

        //return inputStream;
InputStream inputStream= new FileInputStream(file);
return inputStream;
    }
}