/** * Parses the XML content from the given input stream. * * @param input the input stream containing the XML to be parsed * @param checkDtd whether or not download the DTD and validate it * @return the corresponding document * @throws ParserConfigurationException if a SAX parser is not available * @throws SAXException if the document contains a parsing error * @throws IOException if something is seriously wrong. This should not * happen since the input source is known to be constructed from * a string. */ @NonNull public static Document parse(@NonNull InputStream input, boolean checkDtd) throws ParserConfigurationException, SAXException, IOException { // Read in all the data ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; while (true) { int r = input.read(buf); if (r == -1) { break; } out.write(buf, 0, r); } input.close(); return parse(out.toByteArray(), checkDtd); }
/** * @see PositionXmlParser#parse(InputStream, boolean) */ @NonNull public static Document parse(@NonNull InputStream input) throws IOException, SAXException, ParserConfigurationException { return parse(input, true); }
/** * @see PositionXmlParser#parse(byte[], boolean) */ @NonNull public static Document parse(@NonNull byte[] data) throws ParserConfigurationException, SAXException, IOException { return parse(data, true); }
/** * Parses the given XML content. * * @param xml the XML string to be parsed. This must be in the correct * encoding already. * @return the corresponding document * @throws ParserConfigurationException if a SAX parser is not available * @throws SAXException if the document contains a parsing error * @throws IOException if something is seriously wrong. This should not * happen since the input source is known to be constructed from * a string. */ @NonNull public static Document parse(@NonNull String xml) throws ParserConfigurationException, SAXException, IOException { xml = XmlUtils.stripBom(xml); return parse(xml, new InputSource(new StringReader(xml)), true, true); }
return parse(xml, new InputSource(new StringReader(xml)), false, checkDtd);
/** * Parses the XML content from the given byte array * * @param data the raw XML data (with unknown encoding) * @param checkDtd whether or not download the DTD and validate it * @return the corresponding document * @throws ParserConfigurationException if a SAX parser is not available * @throws SAXException if the document contains a parsing error * @throws IOException if something is seriously wrong. This should not * happen since the input source is known to be constructed from * a string. */ @NonNull public static Document parse(@NonNull byte[] data, boolean checkDtd) throws ParserConfigurationException, SAXException, IOException { String xml = getXmlString(data); xml = XmlUtils.stripBom(xml); return parse(xml, new InputSource(new StringReader(xml)), true, checkDtd); }
@NonNull Optional<String> mainManifestPackageName) throws IOException, SAXException, ParserConfigurationException { Document domDocument = PositionXmlParser.parse(inputStream); return new XmlDocument( new SourceFile(xmlFile, displayName),
return PositionXmlParser.parse(xml);
/** * Loads a xml document from its {@link String} representation without doing xml validation and * return a {@link com.android.manifmerger.XmlDocument} * @param sourceFile the source location to use for logging and record collection. * @param xml the persisted xml. * @return the initialized {@link com.android.manifmerger.XmlDocument} * @throws IOException this should never be thrown. * @throws SAXException if the xml is incorrect * @throws ParserConfigurationException if the xml engine cannot be configured. */ @NonNull public static XmlDocument load( @NonNull KeyResolver<String> selectors, @NonNull KeyBasedValueResolver<ManifestSystemProperty> systemPropertyResolver, @NonNull SourceFile sourceFile, @NonNull String xml, @NonNull XmlDocument.Type type, @NonNull Optional<String> mainManifestPackageName) throws IOException, SAXException, ParserConfigurationException { Document domDocument = PositionXmlParser.parse(xml); return new XmlDocument( sourceFile, selectors, systemPropertyResolver, domDocument.getDocumentElement(), type, mainManifestPackageName); } }