本文整理汇总了Java中org.apache.jena.riot.RiotException类的典型用法代码示例。如果您正苦于以下问题:Java RiotException类的具体用法?Java RiotException怎么用?Java RiotException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RiotException类属于org.apache.jena.riot包,在下文中一共展示了RiotException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveToNextBinding
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
protected Binding moveToNextBinding() {
// we need a binding that's ?s ?p ?o
try {
Triple triple = triples.next();
BindingMap binding = BindingFactory.create();
binding.add(Var.alloc("s"), triple.getSubject());
binding.add(Var.alloc("p"), triple.getPredicate());
binding.add(Var.alloc("o"), triple.getObject());
return binding;
} catch (RiotException e) {
// bug in empty results for describe. this is
// a workaround. TODO
}
return BindingFactory.binding();
}
示例2: jsonLdAsJenaModel
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
protected static Model jsonLdAsJenaModel(InputStream jsonIn, URI base)
throws IOException, RiotException {
Model model = ModelFactory.createDefaultModel();
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try {
// TAVERNA-971: set context classloader so jarcache.json is consulted
// even through OSGi
Thread.currentThread().setContextClassLoader(RDFToManifest.class.getClassLoader());
// Now we can parse the JSON-LD without network access
RDFDataMgr.read(model, jsonIn, base.toASCIIString(), Lang.JSONLD);
} finally {
// Restore old context class loader (if any)
Thread.currentThread().setContextClassLoader(oldCl);
}
return model;
}
示例3: load
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
public ModuleHelper load(final URI base,final Format format) throws IOException {
final String data=
new String(
Files.readAllBytes(this.file),
StandardCharsets.UTF_8);
if(!format.equals(Format.RDF_XML) || RDFXMLUtil.isStandaloneDocument(data)) {
try {
this.model =ModelFactory.createDefaultModel();
this.format=format;
final RDFReader reader = this.model.getReader(format.lang.getLabel());
reader.setProperty("error-mode", "strict-fatal");
reader.read(this.model,new StringReader(data),base.toString());
} catch (final RiotException e) {
this.model=null;
this.format=format;
throw new IOException("Parsing failed",e);
}
}
return this;
}
示例4: sendRequest
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
/***************************************************************************
* Private Methods - Handle Translation
**************************************************************************/
private Model sendRequest(HttpServletRequest req, String url)
throws ResponseThrowable
{
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url);
method.setRequestHeader("Accept-Encoding", "gzip");
method.setRequestHeader("Accept" , _format.getMimetype());
InputStream is = null;
try {
int rspCode = client.executeMethod(method);
if ( rspCode != 200 ) { throw new ResponseThrowable(rspCode); }
is = getInputStream(method);
Model m = ModelFactory.createDefaultModel();
m.read(is, null, _format.getJenaFormat().getLang().getLabel());
return m;
}
catch (RiotException | IOException e) {
throw new ResponseThrowable(e, 502);
}
finally { IOUtils.closeQuietly(is); method.releaseConnection(); }
}
示例5: loadModelFromSPARQL
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
public static void loadModelFromSPARQL(Model m, String uri, boolean filter)
{
String sDescribe = buildDESCRIBE(uri);
System.out.println(sDescribe);
QueryEngineHTTP endpoint
= new QueryEngineHTTP(SPARQL_ENDPOINT, sDescribe);
try {
Model mTemp = ModelFactory.createDefaultModel();
endpoint.execDescribe(mTemp);
if ( filter ) { filterSubject(mTemp, uri); }
m.add(mTemp);
}
catch (RiotException e) {
System.out.println("Error: " + e.getMessage());
}
finally {
endpoint.close();
}
}
示例6: cancelMetricAssessment
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
public void cancelMetricAssessment() throws ProcessorNotInitialised {
if(this.isInitalised == false) throw new ProcessorNotInitialised("Streaming will not start as processor has not been initalised");
forcedCancel = true;
for (MetricProcess mp : lstMetricConsumers){
logger.info("Closing and clearing quads queue for {}", mp.metricName);
mp.closeAssessment();
}
logger.info("Closing Iterators");
try{
this.iterator.close();
this.rdfStream.finish();
}catch (RiotException re){
logger.info("RDF Stream already closed");
}
executor.shutdownNow();
}
示例7: cancelMetricAssessment
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
public void cancelMetricAssessment() throws ProcessorNotInitialised {
if(this.isInitalised == false) throw new ProcessorNotInitialised("Streaming will not start as processor has not been initalised");
forcedCancel = true;
for (MetricProcess mp : lstMetricConsumers){
logger.info("Closing and clearing quads queue for {}", mp.metricName);
mp.closeAssessment();
}
logger.info("Closing Iterators");
try{
this.iterator.close();
this.rdfStream.finish();
}catch (RiotException re){
logger.info("RDF Stream already closed");
}
executor.shutdownNow();
}
示例8: testWriteWithException
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Test(expected = WebApplicationException.class)
public void testWriteWithException() throws IOException {
final FutureCallback<Void> callback = new FutureCallback<Void>() {
@Override
public void onSuccess(final Void v) {
throw new AssertionError("Should never happen!");
}
@Override
public void onFailure(final Throwable e) {
LOGGER.info("Got exception:", e.getMessage());
assertTrue("Got wrong kind of exception!", e instanceof RiotException);
}
};
addCallback(testRdfStreamStreamingOutput, callback);
try (final OutputStream mockOutputStream = mock(OutputStream.class, (Answer<Object>) invocation -> {
throw new RiotException("Expected.");
})) {
testRdfStreamStreamingOutput.write(mockOutputStream);
}
}
示例9: harvestFromDumps
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
/**
* Harvests all the triplets from each URI in the @rdfUris list
*/
private void harvestFromDumps() {
for(String uri : rdfUris) {
if(uri.isEmpty()) continue;
logger.info("Harvesting uri [{}]", uri);
Model model = ModelFactory.createDefaultModel();
try {
RDFDataMgr.read(model, uri.trim(), RDFLanguages.RDFXML);
BulkRequestBuilder bulkRequest = client.prepareBulk();
addModelToES(model, bulkRequest, true);
}
catch (RiotException re) {
logger.error("Illegal xml character [{}]", re.getLocalizedMessage());
}
catch (Exception e) {
logger.error("Exception when harvesting url: {}. Details: {}",
uri, e.getLocalizedMessage());
}
}
}
示例10: write
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
public void write(final OutputStream output) {
try {
LOGGER.debug("Serializing RDF stream in: {}", format);
write(rdfStream, output, format, mediaType);
} catch (final IOException | RiotException e) {
setException(e);
LOGGER.debug("Error serializing RDF", e.getMessage());
throw new WebApplicationException(e);
}
}
示例11: read
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
public Stream<? extends Triple> read(final InputStream input, final String base, final RDFSyntax syntax) {
requireNonNull(input, "The input stream may not be null!");
requireNonNull(syntax, "The syntax value may not be null!");
try {
final org.apache.jena.graph.Graph graph = createDefaultGraph();
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeTrellisException("Unsupported RDF Syntax: " + syntax.mediaType()));
RDFParser.source(input).lang(lang).base(base).parse(graph);
// Check the graph for any new namespace definitions
if (nonNull(nsService)) {
final Set<String> namespaces = nsService.getNamespaces().entrySet().stream().map(Map.Entry::getValue)
.collect(toSet());
graph.getPrefixMapping().getNsPrefixMap().forEach((prefix, namespace) -> {
if (!namespaces.contains(namespace)) {
LOGGER.debug("Setting prefix ({}) for namespace {}", prefix, namespace);
nsService.setPrefix(prefix, namespace);
}
});
}
return rdf.asGraph(graph).stream();
} catch (final RiotException | AtlasException ex) {
throw new RuntimeTrellisException(ex);
}
}
示例12: read
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
@Override
public Stream<? extends Triple> read(final InputStream input, final String base, final RDFSyntax syntax) {
requireNonNull(input, "The input stream may not be null!");
requireNonNull(syntax, "The syntax value may not be null!");
try {
final org.apache.jena.graph.Graph graph = createDefaultGraph();
final Lang lang = rdf.asJenaLang(syntax).orElseThrow(() ->
new RuntimeRepositoryException("Unsupported RDF Syntax: " + syntax.mediaType));
RDFParser.source(input).lang(lang).base(base).parse(graph);
// Check the graph for any new namespace definitions
if (nonNull(nsService)) {
final Set<String> namespaces = nsService.getNamespaces().entrySet().stream().map(Map.Entry::getValue)
.collect(toSet());
graph.getPrefixMapping().getNsPrefixMap().forEach((prefix, namespace) -> {
if (!namespaces.contains(namespace)) {
LOGGER.debug("Setting prefix ({}) for namespace {}", prefix, namespace);
nsService.setPrefix(prefix, namespace);
}
});
}
return rdf.asGraph(graph).stream();
} catch (final RiotException | AtlasException ex) {
throw new RuntimeRepositoryException(ex);
}
}
示例13: deserialize
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
private static Dataset deserialize(final String data) {
final DatasetGraph dataset = create();
try (final StringReader reader = new StringReader(data)) {
read(dataset, reader, null, NQUADS);
} catch (final RiotException ex) {
LOGGER.error("Error reading dataset: {}", ex.getMessage());
return null;
}
return rdf.asDataset(dataset);
}
示例14: stringToQuad
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
/**
* Parse a string into a Quad
* @param rdf the RDF object
* @param line the line of text
* @return the Quad
*/
public static Optional<Quad> stringToQuad(final RDF rdf, final String line) {
final DatasetGraph dataset = create();
try {
fromString(line).lang(NQUADS).parse(dataset);
} catch (final RiotException ex) {
LOGGER.warn("Skipping invalid data value: {}", line);
return empty();
}
final Iterator<org.apache.jena.sparql.core.Quad> i = dataset.find();
if (i.hasNext()) {
return of(i.next()).map(x -> asQuad(rdf, x));
}
return empty();
}
示例15: setFormat
import org.apache.jena.riot.RiotException; //导入依赖的package包/类
/**
* Set the format for an input or output, handling ontologies
* @param inputOutput The input or output CWL Element
* @param format The format URI
*/
private void setFormat(CWLElement inputOutput, String format) {
inputOutput.setFormat(format);
try {
if (!rdfService.ontPropertyExists(format)) {
Model ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
ontModel.read(format, null, "RDF/XML");
rdfService.addToOntologies(ontModel);
}
String formatLabel = rdfService.getOntLabel(format);
inputOutput.setType(inputOutput.getType() + " [" + formatLabel + "]");
} catch (RiotException ex) {
inputOutput.setType(inputOutput.getType() + " [format]");
}
}