if (!ArrayUtils.isEmpty(charsets)) {\r
sets.addAll(Arrays.asList(charsets));\r
}\r
+ String value = null;\r
sets.addAll(Arrays.asList("UTF-8", "ISO-8859-1", Charset.defaultCharset().name()));\r
for (String charset : sets) {\r
try {\r
Charset cs = Charset.forName(charset);\r
CharsetDecoder decoder = cs.newDecoder();\r
CharBuffer buffer = decoder.decode(ByteBuffer.wrap(content));\r
- return buffer.toString();\r
+ value = buffer.toString();\r
+ break;\r
} catch (CharacterCodingException e) {\r
// ignore and advance to the next charset\r
} catch (IllegalCharsetNameException e) {\r
// ignore unsupported charsets\r
}\r
}\r
- return new String(content, Charset.forName("UTF-8"));\r
+ value = new String(content, Charset.forName("UTF-8"));\r
+ if (value.startsWith("\uFEFF")) {\r
+ // strip UTF-8 BOM\r
+ return value.substring(1);\r
+ }\r
+ return value;\r
}\r
}
\ No newline at end of file