/** * Checks for the UTF-8 Byte Order Mark, and removes it if present. The SAAJ RI cannot cope with these BOMs. * * @see <a href="http://jira.springframework.org/browse/SWS-393">SWS-393</a> * @see <a href="http://unicode.org/faq/utf_bom.html#22">UTF-8 BOMs</a> */ private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException { PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3); byte[] bytes = new byte[3]; int bytesRead = 0; while (bytesRead < bytes.length) { int n = pushbackInputStream.read(bytes, bytesRead, bytes.length - bytesRead); if (n > 0) { bytesRead += n; } else { break; } } if (bytesRead > 0) { // check for the UTF-8 BOM, and remove it if there. See SWS-393 if (!isByteOrderMark(bytes)) { pushbackInputStream.unread(bytes, 0, bytesRead); } } return pushbackInputStream; }
/** * Checks for the UTF-8 Byte Order Mark, and removes it if present. The SAAJ RI cannot cope with these BOMs. * * @see <a href="http://jira.springframework.org/browse/SWS-393">SWS-393</a> * @see <a href="http://unicode.org/faq/utf_bom.html#22">UTF-8 BOMs</a> */ private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException { PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3); byte[] bytes = new byte[3]; int bytesRead = 0; while (bytesRead < bytes.length) { int n = pushbackInputStream.read(bytes, bytesRead, bytes.length - bytesRead); if (n > 0) { bytesRead += n; } else { break; } } if (bytesRead > 0) { // check for the UTF-8 BOM, and remove it if there. See SWS-393 if (!isByteOrderMark(bytes)) { pushbackInputStream.unread(bytes, 0, bytesRead); } } return pushbackInputStream; }
/** * Checks for the UTF-8 Byte Order Mark, and removes it if present. The SAAJ RI cannot cope with these BOMs. * * @see <a href="http://jira.springframework.org/browse/SWS-393">SWS-393</a> * @see <a href="http://unicode.org/faq/utf_bom.html#22">UTF-8 BOMs</a> */ private InputStream checkForUtf8ByteOrderMark(InputStream inputStream) throws IOException { PushbackInputStream pushbackInputStream = new PushbackInputStream(new BufferedInputStream(inputStream), 3); byte[] bytes = new byte[3]; int bytesRead = 0; while (bytesRead < bytes.length) { int n = pushbackInputStream.read(bytes, bytesRead, bytes.length - bytesRead); if (n > 0) { bytesRead += n; } else { break; } } if (bytesRead > 0) { // check for the UTF-8 BOM, and remove it if there. See SWS-393 if (!isByteOrderMark(bytes)) { pushbackInputStream.unread(bytes, 0, bytesRead); } } return pushbackInputStream; }