use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class RDFParser method parseURI.
/** Parse when there is a URI to guide the choice of syntax */
private void parseURI(StreamRDF destination) {
// Source by uri or path.
try (TypedInputStream input = openTypedInputStream(uri, path)) {
ReaderRIOT reader;
ContentType ct;
if (forceLang != null) {
@SuppressWarnings("deprecation") ReaderRIOTFactory r = RDFParserRegistry.getFactory(forceLang);
if (r == null)
throw new RiotException("No parser registered for language: " + forceLang);
ct = forceLang.getContentType();
reader = createReader(r, forceLang);
} else {
// No forced language.
// Conneg and hint, ignoring text/plain.
ct = WebContent.determineCT(input.getContentType(), hintLang, baseUri);
if (ct == null)
throw new RiotException("Failed to determine the content type: (URI=" + baseUri + " : stream=" + input.getContentType() + ")");
reader = createReader(ct);
if (reader == null)
throw new RiotException("No parser registered for content type: " + ct.getContentType());
}
read(reader, input, null, baseUri, context, ct, destination);
}
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class RDFParser method openTypedInputStream.
@SuppressWarnings("resource")
private TypedInputStream openTypedInputStream(String urlStr, Path path) {
// If path, use that.
if (path != null) {
try {
InputStream in = Files.newInputStream(path);
ContentType ct = RDFLanguages.guessContentType(urlStr);
return new TypedInputStream(in, ct);
} catch (NoSuchFileException | FileNotFoundException ex) {
throw new RiotNotFoundException();
} catch (IOException ex) {
IO.exception(ex);
}
}
TypedInputStream in;
if (urlStr.startsWith("http://") || urlStr.startsWith("https://")) {
// For complete compatibility, we have to let null pass through.
// Pair with RDFParserBuilder.buildHttpClient
// Objects.requireNonNull(httpClient);
// Remap.
urlStr = StreamManager.get(context).mapURI(urlStr);
in = HttpOp.execHttpGet(urlStr, null, httpClient, null);
} else {
in = streamManager.open(urlStr);
}
if (in == null)
throw new RiotNotFoundException("Not found: " + urlStr);
return in;
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class RDFParser method parseNotUri.
/** Parse when there is no URI to guide the choice of syntax */
private void parseNotUri(StreamRDF destination) {
// parse from bytes or chars, no indication of the syntax from the source.
Lang lang = hintLang;
if (forceLang != null)
lang = forceLang;
ContentType ct = WebContent.determineCT(null, lang, baseUri);
if (ct == null)
throw new RiotException("Failed to determine the RDF syntax (.lang or .base required)");
ReaderRIOT readerRiot = createReader(ct);
if (readerRiot == null)
throw new RiotException("No parser registered for content type: " + ct.getContentType());
Reader jr = javaReader;
if (content != null)
jr = new StringReader(content);
read(readerRiot, inputStream, jr, baseUri, context, ct, destination);
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class TestMultipleEmbedded method graphToHttpEntity.
/** Create an HttpEntity for the graph */
protected static HttpEntity graphToHttpEntity(final Graph graph) {
final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS;
ContentProducer producer = new ContentProducer() {
@Override
public void writeTo(OutputStream out) {
RDFDataMgr.write(out, graph, syntax);
}
};
EntityTemplate entity = new EntityTemplate(producer);
ContentType ct = syntax.getLang().getContentType();
entity.setContentType(ct.getContentType());
return entity;
}
use of org.apache.jena.atlas.web.ContentType in project jena by apache.
the class TestEmbeddedFuseki method graphToHttpEntity.
/** Create an HttpEntity for the graph */
protected static HttpEntity graphToHttpEntity(final Graph graph) {
final RDFFormat syntax = RDFFormat.TURTLE_BLOCKS;
ContentProducer producer = new ContentProducer() {
@Override
public void writeTo(OutputStream out) {
RDFDataMgr.write(out, graph, syntax);
}
};
EntityTemplate entity = new EntityTemplate(producer);
ContentType ct = syntax.getLang().getContentType();
entity.setContentType(ct.getContentType());
return entity;
}
Aggregations