List of usage examples for org.apache.commons.io.input BOMInputStream read
@Override public int read() throws IOException
read()
method, detecting and optionally skipping BOM. From source file:org.apache.any23.util.StreamUtils.java
public static Document inputStreamToDocument(InputStream is) throws MalformedByteSequenceException { DocumentBuilderFactory factory = null; DocumentBuilder builder = null; Document doc = null;/* ww w .ja v a 2 s. c om*/ try { factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { logger.error("Error converting InputStream to Document: {}", e); } try { BOMInputStream bomIn = new BOMInputStream(is, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_32BE, ByteOrderMark.UTF_32LE); if (bomIn.hasBOM()) { @SuppressWarnings("unused") int firstNonBOMByte = bomIn.read(); // Skips BOM } doc = builder.parse(bomIn); } catch (SAXException | IOException e) { logger.error("Error converting InputStream to Document: {}", e); } return doc; }