/** * Read an input stream non-destructively to determine the encoding from the Query Prolog * @param is the input stream: this must satisfy the precondition is.markSupported() = true. * @return the encoding to be used: defaults to UTF-8 if no encoding was specified explicitly * in the query prolog * @throws XPathException if the input stream cannot be read */ public static String readEncoding(InputStream is) throws XPathException { try { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must have markSupported() = true"); } is.mark(100); byte[] start = new byte[100]; int read = is.read(start, 0, 100); if (read == -1) { throw new XPathException("Query source file is empty"); } is.reset(); return inferEncoding(start, read); } catch (IOException e) { throw new XPathException("Failed to read query source file", e); } }
/** * Read an input stream non-destructively to determine the encoding from the Query Prolog * * @param is the input stream: this must satisfy the precondition is.markSupported() = true. * @return the encoding to be used: defaults to UTF-8 if no encoding was specified explicitly * in the query prolog * @throws XPathException if the input stream cannot be read */ public static String readEncoding(/*@NotNull*/ InputStream is) throws XPathException { try { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must have markSupported() = true"); } is.mark(100); byte[] start = new byte[100]; int read = is.read(start, 0, 100); if (read == -1) { throw new XPathException("Query source file is empty"); } is.reset(); return inferEncoding(start, read); } catch (IOException e) { throw new XPathException("Failed to read query source file", e); } }
/** * Read an input stream non-destructively to determine the encoding from the Query Prolog * @param is the input stream: this must satisfy the precondition is.markSupported() = true. * @return the encoding to be used: defaults to UTF-8 if no encoding was specified explicitly * in the query prolog * @throws XPathException if the input stream cannot be read */ public static String readEncoding(InputStream is) throws XPathException { try { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must have markSupported() = true"); } is.mark(100); byte[] start = new byte[100]; int read = is.read(start, 0, 100); if (read == -1) { throw new XPathException("Query source file is empty"); } is.reset(); return inferEncoding(start, read); } catch (IOException e) { throw new XPathException("Failed to read query source file", e); } }
/** * Read an input stream non-destructively to determine the encoding from the Query Prolog * * @param is the input stream: this must satisfy the precondition is.markSupported() = true. * @return the encoding to be used: defaults to UTF-8 if no encoding was specified explicitly * in the query prolog * @throws XPathException if the input stream cannot be read */ public static String readEncoding(/*@NotNull*/ InputStream is) throws XPathException { try { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must have markSupported() = true"); } is.mark(100); byte[] start = new byte[100]; int read = is.read(start, 0, 100); if (read == -1) { throw new XPathException("Query source file is empty"); } is.reset(); return inferEncoding(start, read); } catch (IOException e) { throw new XPathException("Failed to read query source file", e); } }