Recommended use of BOMInputStream (#3938)

This commit is contained in:
Yasumichi Akahoshi
2026-01-29 09:48:24 +09:00
committed by GitHub
parent 5fc3dd74a8
commit 6b145ea760

View File

@@ -91,7 +91,10 @@ object StringUtil {
* And if given bytes contains UTF-8 BOM, it's removed from returned string.
*/
def convertFromByteArray(content: Array[Byte]): String =
IOUtils.toString(new BOMInputStream(new java.io.ByteArrayInputStream(content)), detectEncoding(content))
IOUtils.toString(
BOMInputStream.builder().setInputStream(new java.io.ByteArrayInputStream(content)).setInclude(true).get(),
detectEncoding(content)
)
def detectEncoding(content: Array[Byte]): String = {
val detector = new UniversalDetector(null)