I am trying to parse a document that has UTF-8 BOM encoding from a url but I am having problems getting my script to work and remove the first characters 
so that I can use JAXB on the document. I have tried;
Document k = factory.newDocumentBuilder().parse(new URL(url).openStream());
I have also tried;
String defaultEncoding = "UTF-8";
try {
//InputStream inputStream = new FileInputStream(url);
//BOMInputStream bOMInputStream = new BOMInputStream(inputStream);
BOMInputStream bOMInputStream = new BOMInputStream(new URL(url).openStream());
ByteOrderMark bom = bOMInputStream.getBOM();
String charsetName = bom == null ? defaultEncoding : bom.getCharsetName();
InputSource reader = new InputSource(new BufferedInputStream(bOMInputStream)); //, charsetName
reader.setEncoding(charsetName);
System.out.println ("Passed!");
//use reader
Document k = factory.newDocumentBuilder().parse(reader);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
It just does not seem to work.