private void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
private static void read(String base, String name, InputStream is, RepositoryConnection cnx, Resource context) throws RepositoryException { try { cnx.add(is, base, formatFromName(name), context); } catch (IOException x) { LOG.error("Reading. IO problem {}", x.getMessage()); } catch (RDFParseException x) { LOG.error("Reading. RDF parsing problem {}", x.getMessage()); } }
@Test public void testWrongUnicodeEncodedCharFail() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://s> <http://p> \"\\u123X\" <http://g> .".getBytes()); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when an incorrect unicode character is included"); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(30, rdfpe.getColumnNumber()); } }
logger.warn("Could not load {} {}", url, e.getMessage()); String msg = e.getMessage() + " in " + url; throw new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); } catch (IOException e) { logger.warn("Could not load {} {}", url, e.getMessage());
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void import_ (final @Nonnull Object repository, final @Nonnull File file) throws IOException { try { InputStream is = new FileInputStream(file); if (file.getName().endsWith(".gz")) { is = new GZIPInputStream(is); } final Reader r = new InputStreamReader(is, "UTF-8"); ((Repository)repository).getConnection().add(r, "http://foo.bar", RDFFormat.RDFXML); // FIXME r.close(); } catch (RDFParseException e) { throw new IOException(e.toString()); // Java 5/Android compatibility } catch (RepositoryException e) { throw new IOException(e.toString()); // Java 5/Android compatibility } } }
logger.warn("Could not load {} {}", url, e.getMessage()); String msg = e.getMessage() + " in " + url; throw new RDFParseException(msg, e.getLineNumber(), e.getColumnNumber()); } catch (IOException e) { logger.warn("Could not load {} {}", url, e.getMessage());
throw new IOException(e.toString()); // Java 5 / Android compatibility
protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
private Model execGraphQuery(java.net.URI target, String query) { try { log.debug("Executing SPARQL tuple query: {}", query.replaceAll("\\s*[\\r\\n]+\\s*", " ").trim()); RDFFormat format = RDFFormat.TURTLE; CloseableHttpResponse response = client.post(target, query, format.getDefaultMIMEType(),SPARQL_QUERY_MIME_TYPE); final int status = response.getStatusLine().getStatusCode(); log.debug("Request resolved with {} status code: {}", status, response.getStatusLine().getReasonPhrase()); try { if (status >= 200 && status < 300) { String entity = EntityUtils.toString(response.getEntity()); return Rio.parse(new StringReader(entity), target.toString(), RDFFormat.TURTLE, new ParserConfig(), ValueFactoryImpl.getInstance(), new ParseErrorLogger()); } else { // TODO: improve this feedback from the sdk (400, 500, etc) throw new RuntimeException("Query failed: HTTP error code " + status + ": " + response.getStatusLine().getReasonPhrase()); } } catch (RDFParseException e) { log.error("Error parsing query results: {}", e.getMessage(), e); throw new RuntimeException(e); } finally { response.close(); } } catch (IllegalArgumentException | IOException e) { throw new RuntimeException(e); } }
/** * Tests the behaviour with non-whitespace characters after a period * character without a context. * * @throws RDFHandlerException * @throws IOException * @throws RDFParseException */ @Test public void testNonWhitespaceAfterPeriodWithContext() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://www.wrong.com> <http://wrong.com/1.1/tt> \"x\"^^<http://xxx.net/int> <http://path.to.graph> . <thisisnotlegal> ".getBytes()); try { parser.parse(bais, "http://base-uri"); Assert.fail("Expected exception when there is non-whitespace characters after a period."); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(44, rdfpe.getColumnNumber()); } }
logger.error(e.toString(), e); if (schema == null || schema.isEmpty()) throw e;
protected void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
public void testNQuadsFile() throws Exception { RDFParser nquadsParser = createRDFParser(); nquadsParser.setRDFHandler(new AbstractRDFHandler() {}); InputStream in = AbstractNQuadsParserUnitTest.class.getResourceAsStream(NQUADS_TEST_FILE); try { nquadsParser.parse(in, NQUADS_TEST_URL); } catch (RDFParseException e) { fail("NQuadsParser failed to parse N-Quads test document: " + e.getMessage()); } finally { in.close(); } }
/** * Tests the behaviour with non-whitespace characters after a period * character without a context. * * @throws RDFHandlerException * @throws IOException * @throws RDFParseException */ @Test public void testNonWhitespaceAfterPeriodNoContext() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( "<http://www.wrong.com> <http://wrong.com/1.1/tt> \"x\"^^<http://xxx.net/int> . <http://path.to.graph> ".getBytes()); try { parser.parse(bais, "http://base-uri"); Assert.fail("Expected exception when there is non-whitespace characters after a period."); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(44, rdfpe.getColumnNumber()); } }
private void throwEOFException() throws RDFParseException { throw new RDFParseException("Unexpected end of file"); }
public void testNTriplesFileWithReification() throws Exception { RDFParser turtleParser = createRDFParser(); turtleParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); turtleParser.setRDFHandler(new RDFHandlerBase() { public void handleStatement(final Statement st) throws RDFHandlerException { if (log.isInfoEnabled()) log.info("Statement: " + st); } }); final String fileUrl = BigdataNTriplesParser.class.getResource( NTRIPLES_TEST_FILE_WITH_REIFICATION).toExternalForm(); // Note: This is a local copy. InputStream in = BigdataNTriplesParser.class .getResourceAsStream(NTRIPLES_TEST_FILE_WITH_REIFICATION); try { turtleParser.parse(in, fileUrl); } catch (RDFParseException e) { fail("Failed to parse N-Triples test document: " + e.getMessage(), e); } finally { in.close(); } }
@Test public void testStopAtFirstErrorStrictParsing() throws RDFHandlerException, IOException, RDFParseException { final ByteArrayInputStream bais = new ByteArrayInputStream( ("<http://s0> <http://p0> <http://o0> <http://g0> .\n" + "<http://sX> .\n" + // Line // with // error. "<http://s1> <http://p1> <http://o1> <http://g1> .\n").getBytes()); parser.getParserConfig().set(NTriplesParserSettings.FAIL_ON_NTRIPLES_INVALID_LINES, false); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when encountering an invalid line"); } catch (RDFParseException rdfpe) { Assert.assertEquals(2, rdfpe.getLineNumber()); // Assert.assertEquals(50, rdfpe.getColumnNumber()); } }
private void handleException() throws IOException, RDFHandlerException, RDFParseException { if (exception != null) { try { throw exception; } catch (IOException e) { throw e; } catch (RDFHandlerException e) { throw e; } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RDFParseException(e); } } }
/** * The N-Quads parser must be able to parse the N-Triples test file without * error. */ public void testNTriplesFile() throws Exception { RDFParser nquadsParser = createRDFParser(); nquadsParser.setRDFHandler(new AbstractRDFHandler() {}); InputStream in = AbstractNQuadsParserUnitTest.class.getResourceAsStream(NTRIPLES_TEST_FILE); try { nquadsParser.parse(in, NTRIPLES_TEST_URL); } catch (RDFParseException e) { fail("NQuadsParser failed to parse N-Triples test document: " + e.getMessage()); } finally { in.close(); } }
/** * Tests N-Quads parsing with literal and datatype using a prefix, which is * illegal in NQuads, but legal in N3/Turtle that may otherwise look like * NQuads */ @Test public void testParseBasicLiteralDatatypePrefix() throws RDFHandlerException, IOException { final ByteArrayInputStream bais = new ByteArrayInputStream( ("<http://www.v/dat/4b2-21> " + "<http://www.w3.org/20/ica#dtend> " + "\"2010\"^^xsd:integer " + "<http://sin.siteserv.org/def/>.").getBytes()); final TestRDFHandler rdfHandler = new TestRDFHandler(); parser.setRDFHandler(rdfHandler); try { parser.parse(bais, "http://test.base.uri"); Assert.fail("Expected exception when passing in a datatype using an N3 style prefix"); } catch (RDFParseException rdfpe) { Assert.assertEquals(1, rdfpe.getLineNumber()); // FIXME: Enable column numbers when parser supports them // Assert.assertEquals(69, rdfpe.getColumnNumber()); } }