use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class CustomTurtleParserTest method testSES1887NoLangTagFailure.
@Test
public void testSES1887NoLangTagFailure() throws Exception {
try {
Rio.parse(new StringReader("<urn:a> <http://www.example.net/test> \"Foo\"@."), "", RDFFormat.TURTLE);
fail("Did not receive an exception");
} catch (RDFParseException e) {
assertTrue(e.getMessage().contains("Expected a letter, found '.'"));
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class CustomTurtleParserTest method testSES1887NoLangTagFailure2.
@Test
public void testSES1887NoLangTagFailure2() throws Exception {
try {
// NOTE: Bad things may happen when VERIFY_LANGUAGE_TAGS is turned off
// on a file of this structure
Rio.parse(new StringReader("<urn:a> <http://www.example.net/test> \"Foo\"@."), "", RDFFormat.TURTLE, settingsNoVerifyLangTag, vf, errors);
fail("Did not receive an exception");
} catch (RDFParseException e) {
assertTrue(e.getMessage().contains("Unexpected end of file"));
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class CustomTurtleParserTest method testSES2086PeriodEndingLocalNamesFailure1.
@Test
public void testSES2086PeriodEndingLocalNamesFailure1() throws Exception {
try {
Rio.parse(new StringReader("@prefix : <http://example.org> .\n <urn:a> <http://www.example.net/test> :test. ."), "", RDFFormat.TURTLE);
fail("Did not receive an exception");
} catch (RDFParseException e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().contains("Object for statement missing"));
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class SPARQLConnection method add.
@Override
public void add(URL url, String baseURI, RDFFormat dataFormat, Resource... contexts) throws IOException, RDFParseException, RepositoryException {
OpenRDFUtil.verifyContextNotNull(contexts);
// to preserve bnode identity, we need to make sure all statements are
// processed in a single INSERT DATA command
StatementCollector collector = new StatementCollector();
boolean localTransaction = startLocalTransaction();
try {
RDFLoader loader = new RDFLoader(getParserConfig(), getValueFactory());
loader.load(url, baseURI, dataFormat, collector);
add(collector.getStatements(), contexts);
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;
}
}
use of org.eclipse.rdf4j.rio.RDFParseException in project rdf4j by eclipse.
the class RDFLoader method loadZip.
private void loadZip(InputStream in, String baseURI, RDFFormat dataFormat, RDFHandler rdfHandler) throws IOException, RDFParseException, RDFHandlerException {
try (ZipInputStream zipIn = new ZipInputStream(in)) {
for (ZipEntry entry = zipIn.getNextEntry(); entry != null; entry = zipIn.getNextEntry()) {
if (entry.isDirectory()) {
continue;
}
try {
RDFFormat format = Rio.getParserFormatForFileName(entry.getName()).orElse(dataFormat);
// Prevent parser (Xerces) from closing the input stream
UncloseableInputStream wrapper = new UncloseableInputStream(zipIn);
load(wrapper, baseURI, format, rdfHandler);
} catch (RDFParseException e) {
String msg = e.getMessage() + " in " + entry.getName();
RDFParseException pe = new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber());
pe.initCause(e);
throw pe;
} finally {
zipIn.closeEntry();
}
}
// end for
}
}
Aggregations