Fix problem detecting boundary with streams that return a single byte at a time
@@ -157,8 +157,15 @@ public class AttachmentDeserializer {
PushbackInputStream in = new PushbackInputStream(is, 4096);
byte buf[] = new byte[2048];
int i = in.read(buf);
- String msg = IOUtils.newStringFromBytes(buf, 0, i);
- in.unread(buf, 0, i);
+ int len = i;
+ while (i > 0 && len < buf.length) {
+ i = in.read(buf, len, buf.length - len);
+ if (i > 0) {
+ len += i;
+ }
+ }
+ String msg = IOUtils.newStringFromBytes(buf, 0, len);
+ in.unread(buf, 0, len);
// Reset the input stream since we'll need it again later
message.setContent(InputStream.class, in);
