void loadDocument(InputStream in, final String encoding, DocumentListener documentListener) throws IOException {
// If the encoding is UTF-something, wrap the stream in a BOMInputStream to filter out the byte-order mark
// (see ticket #245)
if(encoding != null && encoding.toLowerCase().startsWith("utf")) {
in = new BOMInputStream(in);
}
// If the given encoding is invalid (null or not supported), default to "UTF-8"
this.encoding = encoding==null || !Charset.isSupported(encoding) ? "UTF-8" : encoding;