当一个文件用慢速连接上传时(仅),使用我的CXF REST API,我得到的是 Couldn't find MIME boundary
错误。于是我对CXF核心代码进行了调试,找到了原因。现在我看到了这段CXF核心代码[1]。
private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException {
// work around a bug in PushBackInputStream where the buffer isn't
// initialized
// and available always returns 0.
int value = pbs.read();
pbs.unread(value);
while (value != -1) {
value = pbs.read();
当客户端到服务器的连接速度非常慢时,输入流的第一个值几乎都是 -1
. 其结果是 Couldn't find MIME boundary
在流程的后面出现了错误。
如果我像下面一样把代码改成跳过第一个字节,如果是-1,就能顺利工作。
private static boolean readTillFirstBoundary(PushbackInputStream pbs, byte[] bp) throws IOException {
// work around a bug in PushBackInputStream where the buffer isn't
// initialized
// and available always returns 0.
int value = pbs.read();
if (value == -1) { <<<<<< if the first byte is -1,
value = pbs.read(); <<<<<< ignore that and read the
} <<<<<< next byte
pbs.unread(value);
while (value != -1) {
value = pbs.read();
知道是什么原因吗?