public void parseCharArray(char[] input, int offset, int end, int startingLineNr) { try { Reader reader = new CharArrayReader(input, offset, end); parseImpl(reader, startingLineNr); } catch (IOException e) { // This exception will never happen. } }
public void parseReader(Reader r) throws IOException { parseImpl(r, 1); }
public void parseStream(InputStream input, int startingLineNr, boolean autoClose) throws IOException { // check input encoding if present removeChildren(); BufferedInputStream bin; if (input instanceof BufferedInputStream) { bin = (BufferedInputStream) input; } else { bin = new BufferedInputStream(input); } bin.mark(1024); BufferedReader encodedReader = null; int ch = bin.read(); while (ch >= 0 && (ch == '\n' || ch == '\t' || ch == ' ' || ch == '\r')) { ch = bin.read(); } if (ch == '<') { ch = bin.read(); if (ch == '?') { StringBuffer buf = new StringBuffer("<?"); ch = bin.read(); while (ch >= 0 && ch != '?') { buf.append((char) ch); ch = bin.read(); } if (ch == '?') { buf.append((char) ch); } ch = bin.read(); if (ch == '>') { buf.append((char) ch); } String xmlLine = buf.toString(); int k = xmlLine.indexOf("encoding"); if (k >= 0) { k = xmlLine.indexOf('=', k); if (k >= 0) { k = xmlLine.indexOf('"', k); if (k >= 0) { int m = xmlLine.indexOf('"', k + 1); if (m >= 0) { String encoding = xmlLine.substring(k + 1, m); // replace input reader bin.reset(); encodedReader = new BufferedReader(new InputStreamReader(bin, encoding)); } } } } } } // do not close bin if (encodedReader == null) { bin.reset(); encodedReader = new BufferedReader(new InputStreamReader(bin)); } try { parseImpl(encodedReader, 1); } finally { if (autoClose) { encodedReader.close(); } } }