/** * Read a query from an InputStream. The method checks that all characters are valid XML * characters, and also performs normalization of line endings. * @param is the input stream * @param encoding the encoding, or null if the encoding is unknown * @param nameChecker the nameChecker to be used for checking characters * @return the content of the InputStream as a string */ public static String readInputStream(InputStream is, String encoding, NameChecker nameChecker) throws XPathException { if (encoding == null) { if (!is.markSupported()) { is = new BufferedInputStream(is); } encoding = readEncoding(is); } try { Reader reader = new BufferedReader(new InputStreamReader(is, encoding)); return readQueryFromReader(reader, nameChecker); } catch (UnsupportedEncodingException encErr) { throw new XPathException("Unknown encoding " + Err.wrap(encoding), encErr); } }
/** * Read a query from an InputStream. The method checks that all characters are valid XML * characters, and also performs normalization of line endings. * @param is the input stream * @param encoding the encoding, or null if the encoding is unknown * @param nameChecker the nameChecker to be used for checking characters * @return the content of the InputStream as a string */ public static String readInputStream(InputStream is, String encoding, NameChecker nameChecker) throws XPathException { if (encoding == null) { if (!is.markSupported()) { is = new BufferedInputStream(is); } encoding = readEncoding(is); } try { Reader reader = new BufferedReader(new InputStreamReader(is, encoding)); return readQueryFromReader(reader, nameChecker); } catch (UnsupportedEncodingException encErr) { throw new XPathException("Unknown encoding " + Err.wrap(encoding), encErr); } }
/** * Read a query from an InputStream. The method checks that all characters are valid XML * characters, and also performs normalization of line endings. * * @param is the input stream * @param encoding the encoding, or null if the encoding is unknown * @param nameChecker the predicate to be used for checking characters * @return the content of the InputStream as a string */ public static String readInputStream(InputStream is, String encoding, IntPredicate nameChecker) throws XPathException { if (encoding == null) { if (!is.markSupported()) { is = new BufferedInputStream(is); } encoding = readEncoding(is); } try { Reader reader = new BufferedReader(new InputStreamReader(is, encoding)); return readQueryFromReader(reader, nameChecker); } catch (UnsupportedEncodingException encErr) { XPathException err = new XPathException("Unknown encoding " + Err.wrap(encoding), encErr); err.setErrorCode("XQST0087"); throw err; } }
/** * Read a query from an InputStream. The method checks that all characters are valid XML * characters, and also performs normalization of line endings. * * @param is the input stream * @param encoding the encoding, or null if the encoding is unknown * @param nameChecker the predicate to be used for checking characters * @return the content of the InputStream as a string */ public static String readInputStream(InputStream is, String encoding, IntPredicate nameChecker) throws XPathException { if (encoding == null) { if (!is.markSupported()) { is = new BufferedInputStream(is); } encoding = readEncoding(is); } try { Reader reader = new BufferedReader(new InputStreamReader(is, encoding)); return readQueryFromReader(reader, nameChecker); } catch (UnsupportedEncodingException encErr) { XPathException err = new XPathException("Unknown encoding " + Err.wrap(encoding), encErr); err.setErrorCode("XQST0087"); throw err; } }
/** * Read a query module given a StreamSource * * @param ss the supplied StreamSource. This must contain a non-null systemID which defines the base * URI of the query module, and either an InputStream or a Reader containing the query text. In the * case of an InputStream the method attempts to infer the encoding; in the case of a Reader, this has * already been done, and the encoding specified within the query itself is ignored. * <p>The method reads from the InputStream or Reader contained in the StreamSource up to the end * of file unless a fatal error occurs. It does not close the InputStream or Reader; this is the caller's * responsibility.</p> * @param charChecker this checks XML characters against either the XML 1.0 or XML 1.1 rules * @return the text of the query */ public static String readSourceQuery(/*@NotNull*/ StreamSource ss, IntPredicate charChecker) throws XPathException { CharSequence queryText; if (ss.getInputStream() != null) { InputStream is = ss.getInputStream(); if (!is.markSupported()) { is = new BufferedInputStream(is); } String encoding = readEncoding(is); queryText = readInputStream(is, encoding, charChecker); } else if (ss.getReader() != null) { queryText = readQueryFromReader(ss.getReader(), charChecker); } else { throw new XPathException("Module URI Resolver must supply either an InputStream or a Reader"); } return queryText.toString(); }
/** * Read a query module given a StreamSource * @param ss the supplied StreamSource. This must contain a non-null systemID which defines the base * URI of the query module, and either an InputStream or a Reader containing the query text. In the * case of an InputStream the method attempts to infer the encoding; in the case of a Reader, this has * already been done, and the encoding specified within the query itself is ignored. * <p>The method reads from the InputStream or Reader contained in the StreamSource up to the end * of file unless a fatal error occurs. It does not close the InputStream or Reader; this is the caller's * responsibility.</p> * @param nameChecker this checks XML names against either the XML 1.0 or XML 1.1 rules * @return the text of the query */ public static String readSourceQuery(StreamSource ss, NameChecker nameChecker) throws XPathException { CharSequence queryText; if (ss.getInputStream() != null) { InputStream is = ss.getInputStream(); if (!is.markSupported()) { is = new BufferedInputStream(is); } String encoding = readEncoding(is); queryText = readInputStream(is, encoding, nameChecker); } else if (ss.getReader() != null) { queryText = readQueryFromReader(ss.getReader(), nameChecker); } else { throw new XPathException("Module URI Resolver must supply either an InputSource or a Reader"); } return queryText.toString(); }
/** * Read a query module given a StreamSource * @param ss the supplied StreamSource. This must contain a non-null systemID which defines the base * URI of the query module, and either an InputStream or a Reader containing the query text. In the * case of an InputStream the method attempts to infer the encoding; in the case of a Reader, this has * already been done, and the encoding specified within the query itself is ignored. * <p>The method reads from the InputStream or Reader contained in the StreamSource up to the end * of file unless a fatal error occurs. It does not close the InputStream or Reader; this is the caller's * responsibility.</p> * @param nameChecker this checks XML names against either the XML 1.0 or XML 1.1 rules * @return the text of the query */ public static String readSourceQuery(StreamSource ss, NameChecker nameChecker) throws XPathException { CharSequence queryText; if (ss.getInputStream() != null) { InputStream is = ss.getInputStream(); if (!is.markSupported()) { is = new BufferedInputStream(is); } String encoding = readEncoding(is); queryText = readInputStream(is, encoding, nameChecker); } else if (ss.getReader() != null) { queryText = readQueryFromReader(ss.getReader(), nameChecker); } else { throw new XPathException("Module URI Resolver must supply either an InputSource or a Reader"); } return queryText.toString(); }
/** * Read a query module given a StreamSource * * @param ss the supplied StreamSource. This must contain a non-null systemID which defines the base * URI of the query module, and either an InputStream or a Reader containing the query text. In the * case of an InputStream the method attempts to infer the encoding; in the case of a Reader, this has * already been done, and the encoding specified within the query itself is ignored. * <p>The method reads from the InputStream or Reader contained in the StreamSource up to the end * of file unless a fatal error occurs. It does not close the InputStream or Reader; this is the caller's * responsibility.</p> * @param charChecker this checks XML characters against either the XML 1.0 or XML 1.1 rules * @return the text of the query */ public static String readSourceQuery(/*@NotNull*/ StreamSource ss, IntPredicate charChecker) throws XPathException { CharSequence queryText; if (ss.getInputStream() != null) { InputStream is = ss.getInputStream(); if (!is.markSupported()) { is = new BufferedInputStream(is); } String encoding = readEncoding(is); queryText = readInputStream(is, encoding, charChecker); } else if (ss.getReader() != null) { queryText = readQueryFromReader(ss.getReader(), charChecker); } else { throw new XPathException("Module URI Resolver must supply either an InputStream or a Reader"); } return queryText.toString(); }