Example usage for org.apache.commons.io.input BOMInputStream BOMInputStream

List of usage examples for org.apache.commons.io.input BOMInputStream BOMInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input BOMInputStream BOMInputStream.

Prototype

public BOMInputStream(InputStream delegate, ByteOrderMark... boms) 

Source Link

Document

Constructs a new BOM InputStream that excludes the specified BOMs.

Usage

From source file:org.openrdf.rio.rdfjson.RDFJSONParser.java

@Override
public void parse(final InputStream inputStream, final String baseUri)
        throws IOException, RDFParseException, RDFHandlerException {
    if (this.rdfHandler != null) {
        this.rdfHandler.startRDF();
    }/*from  w  w  w . ja  v a 2  s.c  o m*/

    JsonParser jp = null;

    try {
        jp = RDFJSONUtility.JSON_FACTORY.createParser(new BOMInputStream(inputStream, false));
        rdfJsonToHandlerInternal(this.rdfHandler, this.valueFactory, jp);
    } catch (final IOException e) {
        if (jp != null) {
            reportFatalError("Found IOException during parsing", e, jp.getCurrentLocation());
        } else {
            reportFatalError(e);
        }
    } finally {
        clear();
        if (jp != null) {
            try {
                jp.close();
            } catch (final IOException e) {
                reportFatalError("Found exception while closing JSON parser", e, jp.getCurrentLocation());
            }
        }
    }
    if (this.rdfHandler != null) {
        this.rdfHandler.endRDF();
    }
}

From source file:org.openrdf.rio.trix.TriXParser.java

public void parse(InputStream in, String baseURI) throws IOException, RDFParseException, RDFHandlerException {
    parse(new BOMInputStream(in, false));
}

From source file:org.openrdf.rio.turtle.TurtleParser.java

/**
 * Implementation of the <tt>parse(InputStream, String)</tt> method defined
 * in the RDFParser interface./*from   w  w w .jav a2s .c o  m*/
 * 
 * @param in
 *        The InputStream from which to read the data, must not be
 *        <tt>null</tt>. The InputStream is supposed to contain UTF-8 encoded
 *        Unicode characters, as per the Turtle specification.
 * @param baseURI
 *        The URI associated with the data in the InputStream, must not be
 *        <tt>null</tt>.
 * @throws IOException
 *         If an I/O error occurred while data was read from the InputStream.
 * @throws RDFParseException
 *         If the parser has found an unrecoverable parse error.
 * @throws RDFHandlerException
 *         If the configured statement handler encountered an unrecoverable
 *         error.
 * @throws IllegalArgumentException
 *         If the supplied input stream or base URI is <tt>null</tt>.
 */
public synchronized void parse(InputStream in, String baseURI)
        throws IOException, RDFParseException, RDFHandlerException {
    if (in == null) {
        throw new IllegalArgumentException("Input stream must not be 'null'");
    }
    // Note: baseURI will be checked in parse(Reader, String)

    try {
        parse(new InputStreamReader(new BOMInputStream(in, false), "UTF-8"), baseURI);
    } catch (UnsupportedEncodingException e) {
        // Every platform should support the UTF-8 encoding...
        throw new RuntimeException(e);
    }
}