Search in sources :

Example 6 with ParseErrorLogger

use of org.eclipse.rdf4j.rio.helpers.ParseErrorLogger in project rdf4j by eclipse.

the class RDFLoader method loadInputStreamOrReader.

/**
 * Adds the data that can be read from the supplied InputStream or Reader to
 * this repository.
 *
 * @param inputStreamOrReader
 *            An {@link InputStream} or {@link Reader} containing RDF data
 *            that must be added to the repository.
 * @param baseURI
 *            The base URI for the data.
 * @param dataFormat
 *            The file format of the data.
 * @param rdfHandler
 *            handles all data from all documents
 * @throws IOException
 * @throws UnsupportedRDFormatException
 * @throws RDFParseException
 * @throws RDFHandlerException
 */
private void loadInputStreamOrReader(Object inputStreamOrReader, String baseURI, RDFFormat dataFormat, RDFHandler rdfHandler) throws IOException, RDFParseException, RDFHandlerException {
    RDFParser rdfParser = Rio.createParser(dataFormat, vf);
    rdfParser.setParserConfig(config);
    rdfParser.setParseErrorListener(new ParseErrorLogger());
    rdfParser.setRDFHandler(rdfHandler);
    if (inputStreamOrReader instanceof InputStream) {
        rdfParser.parse((InputStream) inputStreamOrReader, baseURI);
    } else if (inputStreamOrReader instanceof Reader) {
        rdfParser.parse((Reader) inputStreamOrReader, baseURI);
    } else {
        throw new IllegalArgumentException("Must be an InputStream or a Reader, is a: " + inputStreamOrReader.getClass());
    }
}
Also used : ParseErrorLogger(org.eclipse.rdf4j.rio.helpers.ParseErrorLogger) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) UncloseableInputStream(org.eclipse.rdf4j.common.io.UncloseableInputStream) InputStream(java.io.InputStream) Reader(java.io.Reader) RDFParser(org.eclipse.rdf4j.rio.RDFParser)

Aggregations

ParseErrorLogger (org.eclipse.rdf4j.rio.helpers.ParseErrorLogger)6 StringReader (java.io.StringReader)3 Model (org.eclipse.rdf4j.model.Model)3 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)3 ParserConfig (org.eclipse.rdf4j.rio.ParserConfig)3 RDFParser (org.eclipse.rdf4j.rio.RDFParser)3 Test (org.junit.Test)3 HttpResponse (org.apache.http.HttpResponse)2 NamespaceImpl (org.eclipse.rdf4j.model.impl.NamespaceImpl)2 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)2 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)2 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Reader (java.io.Reader)1 Charset (java.nio.charset.Charset)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1