Java Code Examples for org.eclipse.rdf4j.rio.RDFHandlerException#getCause()

The following examples show how to use org.eclipse.rdf4j.rio.RDFHandlerException#getCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SailUpdateExecutor.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void executeLoad(Load load, UpdateContext uc) throws IOException, RDFParseException, SailException {
	Value source = load.getSource().getValue();
	Value graph = load.getGraph() != null ? load.getGraph().getValue() : null;

	URL sourceURL = new URL(source.stringValue());

	RDFSailInserter rdfInserter = new RDFSailInserter(con, vf, uc);
	if (graph != null) {
		rdfInserter.enforceContext((Resource) graph);
	}
	try {
		loader.load(sourceURL, source.stringValue(), null, rdfInserter);
	} catch (RDFHandlerException e) {
		// RDFSailInserter only throws wrapped SailExceptions
		throw (SailException) e.getCause();
	}
}
 
Example 2
Source File: ContextAwareConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void removeWithoutCommit(Resource subject, IRI predicate, Value object, Resource... contexts)
		throws RepositoryException {
	IRI[] archiveContexts = getArchiveContexts();
	if (archiveContexts.length > 0) {
		RDFHandler handler = new RDFInserter(getDelegate());
		try {
			getDelegate().exportStatements(subject, predicate, object, true, handler, archiveContexts);
		} catch (RDFHandlerException e) {
			if (e.getCause() instanceof RepositoryException) {
				throw (RepositoryException) e.getCause();
			}
			throw new AssertionError(e);
		}
	}
	if (isAllContext(contexts)) {
		getDelegate().remove(subject, predicate, object, getRemoveContexts());
	} else {
		getDelegate().remove(subject, predicate, object, contexts);
	}
}
 
Example 3
Source File: RDFXMLPrettyWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void flush() throws IOException {
	if (isWritingStarted()) {
		if (!headerWritten) {
			writeHeader();
		}

		try {
			flushPendingStatements();
		} catch (RDFHandlerException e) {
			if (e.getCause() != null && e.getCause() instanceof IOException) {
				throw (IOException) e.getCause();
			} else {
				throw new IOException(e);
			}
		}

		writer.flush();
	}
}
 
Example 4
Source File: RDFXMLPrettyWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void close() throws IOException {
	try {
		if (isWritingStarted() && !writingEnded) {
			endRDF();
		}
	} catch (RDFHandlerException e) {
		if (e.getCause() != null && e.getCause() instanceof IOException) {
			throw (IOException) e.getCause();
		} else {
			throw new IOException(e);
		}
	} finally {
		nodeStack.clear();
		predicateStack.clear();
		writer.close();
	}
}
 
Example 5
Source File: QueryResultIO.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Writes a graph query result document in a specific RDF format to an output stream.
 *
 * @param gqr    The query result to write.
 * @param format The file format of the document to write.
 * @param out    An OutputStream to write the document to.
 * @throws IOException                  If an I/O error occurred while writing the query result document to the
 *                                      stream.
 * @throws RDFHandlerException          If such an exception is thrown by the used RDF writer.
 * @throws QueryEvaluationException
 * @throws UnsupportedRDFormatException If an unsupported query result file format was specified.
 */
public static void writeGraph(GraphQueryResult gqr, RDFFormat format, OutputStream out)
		throws IOException, RDFHandlerException, UnsupportedRDFormatException, QueryEvaluationException {
	RDFWriter writer = Rio.createWriter(format, out);
	try {
		QueryResults.report(gqr, writer);
	} catch (RDFHandlerException e) {
		if (e.getCause() instanceof IOException) {
			throw (IOException) e.getCause();
		} else {
			throw e;
		}
	}
}