Skip to content

Commit e2f10c3

Browse files
author
Arjen Poutsma
committed
Improved checkForUtf8ByteOrderMark
Improved algorithm to check for UTF-8 Byte Order Marks. No longer expect all three starting bytes to be read at once, but reads them as blocks. Issue: SWS-845
1 parent 1ff4d47 commit e2f10c3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessageFactory.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,16 @@ private MimeHeaders parseMimeHeaders(InputStream inputStream) throws IOException
251251
private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException {
252252
PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3);
253253
byte[] bytes = new byte[3];
254-
int bytesRead = pushbackInputStream.read(bytes);
255-
if (bytesRead != -1) {
254+
int bytesRead = 0;
255+
while (bytesRead < bytes.length) {
256+
int n = pushbackInputStream.read(bytes, bytesRead, bytes.length - bytesRead);
257+
if (n > 0) {
258+
bytesRead += n;
259+
} else {
260+
break;
261+
}
262+
}
263+
if (bytesRead > 0) {
256264
// check for the UTF-8 BOM, and remove it if there. See SWS-393
257265
if (!isByteOrderMark(bytes)) {
258266
pushbackInputStream.unread(bytes, 0, bytesRead);

0 commit comments

Comments
 (0)