Search in sources :

Example 1 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project graal by graphik-team.

the class Producer method run.

@Override
public void run() {
    org.eclipse.rdf4j.rio.RDFParser rdfParser = Rio.createParser(format);
    if (this.config != null) {
        rdfParser.setParserConfig(config);
    }
    rdfParser.setRDFHandler(new RDFListener(buffer));
    try {
        rdfParser.parse(this.reader, "");
    } catch (RDFParseException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (RDFHandlerException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (IOException e) {
        throw new ParseError("An error occured while parsing", e);
    }
    buffer.close();
    try {
        this.reader.close();
    } catch (IOException e) {
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) IOException(java.io.IOException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 2 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class TestTurtleParser method testParseBooleanLiteralWhitespaceSemicolumn.

@Test
public void testParseBooleanLiteralWhitespaceSemicolumn() throws Exception {
    String data = "<urn:a> <urn:b> true ; <urn:c> false .";
    Reader r = new StringReader(data);
    try {
        parser.parse(r, baseURI);
        assertTrue(statementCollector.getStatements().size() == 2);
    } catch (RDFParseException e) {
        fail("parse error on correct data: " + e.getMessage());
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 3 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class TestTurtleParser method testLineNumberReporting.

@Test
public void testLineNumberReporting() throws Exception {
    InputStream in = this.getClass().getResourceAsStream("/test-newlines.ttl");
    try {
        parser.parse(in, baseURI);
        fail("expected to fail parsing input file");
    } catch (RDFParseException e) {
        // expected
        assertFalse(errorCollector.getFatalErrors().isEmpty());
        final String error = errorCollector.getFatalErrors().get(0);
        // expected to fail at line 9.
        assertTrue(error.contains("(9,"));
        assertEquals(9, locationListener.getLineNo());
        assertEquals(-1, locationListener.getColumnNo());
    }
}
Also used : InputStream(java.io.InputStream) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 4 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class TestTurtleParser method testParseBooleanLiteralComma.

@Test
public void testParseBooleanLiteralComma() throws Exception {
    String data = "<urn:a> <urn:b> true, false .";
    Reader r = new StringReader(data);
    try {
        parser.parse(r, baseURI);
        assertTrue(statementCollector.getStatements().size() == 2);
    } catch (RDFParseException e) {
        fail("parse error on correct data: " + e.getMessage());
    }
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 5 with RDFParseException

use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.

the class AbstractRepositoryConnection method add.

@Override
public void add(File file, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
    OpenRDFUtil.verifyContextNotNull(contexts);
    RDFInserter rdfInserter = new RDFInserter(this);
    rdfInserter.enforceContext(contexts);
    boolean localTransaction = startLocalTransaction();
    try {
        RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
        loader.load(file, baseURI, dataFormat, rdfInserter);
        conditionalCommit(localTransaction);
    } catch (RDFHandlerException e) {
        conditionalRollback(localTransaction);
        // RDFInserter only throws wrapped RepositoryExceptions
        throw (RepositoryException) e.getCause();
    } catch (RDFParseException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (IOException e) {
        conditionalRollback(localTransaction);
        throw e;
    } catch (RuntimeException e) {
        conditionalRollback(localTransaction);
        throw e;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) RDFInserter(org.eclipse.rdf4j.repository.util.RDFInserter) IOException(java.io.IOException) RDFLoader(org.eclipse.rdf4j.repository.util.RDFLoader) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Aggregations

RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)50 Test (org.junit.Test)22 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)19 IOException (java.io.IOException)16 StringReader (java.io.StringReader)13 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)9 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)8 Model (org.eclipse.rdf4j.model.Model)7 RDFParser (org.eclipse.rdf4j.rio.RDFParser)7 Statement (org.eclipse.rdf4j.model.Statement)6 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)6 RepositoryException (org.eclipse.rdf4j.repository.RepositoryException)5 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Reader (java.io.Reader)4 RDFInserter (org.eclipse.rdf4j.repository.util.RDFInserter)4 SAXException (org.xml.sax.SAXException)4 IRI (org.eclipse.rdf4j.model.IRI)3 Literal (org.eclipse.rdf4j.model.Literal)3