java - 输入流以 -1 开头
问题描述
当使用我的 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();
知道可能是什么原因吗?
解决方案
原来是一个 tomcat 错误[1]。:-/
适用于更高版本的 Tomcat 的文件。
推荐阅读
- google-apps-script - 可以缓存谷歌脚本对象吗?
- postgresql - 如何在 Doobie (Postgres) 中读取/写入时间戳
- javascript - 使用 ES6 优化 javascript 中的递归类别和子类别函数
- c++ - 在双数组的 calloc 上写入大小为 8 的无效
- vb.net - 来自文本文件的数据库路径
- neo4j - 在 Neo4j 中为关系设置属性
- react-native - React Native 文本和图像并排对齐问题
- netlogo - 如何在 NetLogo 中改变随机海龟的颜色
- java - SpEL Spring中的三元运算符
- c# - Windows 身份验证:用户 'DOMAIN\MACHINE$' 登录失败