ValueResourceParser2 { @NonNull static Document parseDocument(@NonNull File file, boolean trackPositions) throws MergingException { try { if (trackPositions) { return PositionXmlParser.parse(new BufferedInputStream(new FileInputStream(file))); } else { return XmlUtils.parseUtfXmlFile(file, true); } } catch (SAXException e) { throw MergingException.wrapException(e).withFile(file).build(); } catch (ParserConfigurationException e) { throw MergingException.wrapException(e).withFile(file).build(); } catch (IOException e) { throw MergingException.wrapException(e).withFile(file).build(); } } ValueResourceParser2(@NonNull File file, @Nullable String libraryName);   }
@Test public void testUtfBom() throws IOException, MergingException { File file = File.createTempFile("testUtfBom", SdkConstants.DOT_XML); String xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<LinearLayout xmlns:android=\"http: " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:orientation=\"vertical\" >\n" + "\n" + " <Button\n" + " android:id=\"@+id/button1\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:text=\"Button\" />\n" + " some text\n" + "\n" + "</LinearLayout>\n"; BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(file)); OutputStreamWriter writer = new OutputStreamWriter(stream, Charsets.UTF_8); stream.write(0xef); stream.write(0xbb); stream.write(0xbf); writer.write(xml); writer.close(); Document document = ValueResourceParser2.parseDocument(file, false); assertNotNull(document); assertNotNull(document.getDocumentElement()); assertEquals("LinearLayout", document.getDocumentElement().getTagName()); file.delete(); }