Package org.aksw.jenax.sparql.query.rx
Class RDFDataMgrEx
java.lang.Object
org.aksw.jenax.sparql.query.rx.RDFDataMgrEx
Extensions to help open an InputStream of unknown content using probing against languages registered to the Jena riot system.
This includes languages based on triples, quads and result sets. Support for further types may be added in the future.
- Author:
- Claus Stadler, Dec 18, 2018
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InputStreamdecode(InputStream in, List<String> codecs) static InputStreamdecode(InputStream in, List<String> codecs, org.apache.commons.compress.compressors.CompressorStreamFactory csf) Decode a given input stream based on a sequence of codec names.static OutputStreamencode(OutputStream out, List<String> codecs, org.apache.commons.compress.compressors.CompressorStreamFactory csf) static Function<OutputStream,OutputStream> static Function<OutputStream,OutputStream> static Function<OutputStream,OutputStream> static InputStreamstatic org.apache.jena.atlas.web.TypedInputStreamforceBuffered(org.apache.jena.atlas.web.TypedInputStream tin) Return a TypedInputStream whose underlying InputStream supports marks If the original one already supports it it is returned as is.static org.apache.jena.riot.LanggetLang(org.apache.jena.atlas.web.TypedInputStream tin) Map a TypedInputStream's media type to a Langstatic booleanstatic org.apache.jena.query.DatasetloadDatasetAsGiven(String uri, String baseIri) static org.apache.jena.rdf.model.ModelloadModelAsGiven(String uri) static org.apache.jena.riot.RDFParserBuildernewParserBuilderForReadAsGiven(String baseIri) Return a preconfigured parser builder that retains blank node ids and relative IRIsstatic org.apache.jena.atlas.web.TypedInputStreamstatic org.apache.jena.atlas.web.TypedInputStreamopen(String src, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) Attempts to open the given src and probe for the content type Src may be '-' but not NULL in order to refer to STDIN.static org.apache.jena.atlas.web.TypedInputStreamstatic org.apache.jena.atlas.web.TypedInputStreamopen(Path path, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) open via niostatic org.apache.jena.query.DatasetparseTrigAgainstDataset(org.apache.jena.query.Dataset dataset, org.apache.jena.shared.PrefixMapping prefixMapping, InputStream in) static org.apache.jena.rdf.model.ModelparseTurtleAgainstModel(org.apache.jena.rdf.model.Model model, org.apache.jena.shared.PrefixMapping prefixMapping, InputStream in) Parse the input stream as turtle, thereby prepending a serialization of the given prefix mapping.static voidpeek(InputStream in) static InputStreamprependWithPrefixes(InputStream in, org.apache.jena.shared.PrefixMapping prefixMapping) Convenience method to prepend prefixes to an input stream (in turtle syntax)static InputStreamprependWithPrefixes(InputStream in, org.apache.jena.shared.PrefixMapping prefixMapping, org.apache.jena.riot.RDFFormat fmt) Convenience method to prepend prefixes to an input stream (in a given format)static org.apache.jena.atlas.web.TypedInputStreamprependWithPrefixes(org.apache.jena.atlas.web.TypedInputStream in, org.apache.jena.shared.PrefixMapping prefixMapping) static org.apache.jena.query.DatasetprintParseRoundtrip(org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat, org.apache.jena.query.Dataset result) Serialize a dataset in memory and return its deserialized version.static org.apache.jena.rdf.model.ModelprintParseRoundtrip(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat, org.apache.jena.rdf.model.Model result) Serialize a model in memory and return its deserialized version.static InputStreamprobeEncodings(InputStream is, List<String> outEncodings) Given an input stream with mark support, attempt to create a decoded input stream.static RdfEntityInfoprobeEntityInfo(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates) This method closes the input stream when it returns.static RdfEntityInfoprobeEntityInfo(Path path, Iterable<org.apache.jena.riot.Lang> candidates) static RdfEntityInfoprobeEntityInfo(Callable<InputStream> inSupp, Iterable<org.apache.jena.riot.Lang> candidates) Probe an input stream for any encodings (e.g.static org.apache.jena.atlas.web.TypedInputStreamprobeForSpecificLang(org.apache.jena.atlas.web.TypedInputStream result, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) static org.apache.jena.atlas.web.TypedInputStreamprobeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates) Determine the RDF content of the given input stream.static org.apache.jena.atlas.web.TypedInputStreamprobeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, boolean tryAllCandidates) static org.apache.jena.atlas.web.TypedInputStreamprobeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, boolean tryAllCandidates, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) Probe the content of the input stream against a given set of candidate languages.static org.apache.jena.atlas.web.TypedInputStreamprobeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) static voidread(org.apache.jena.rdf.model.Model model, org.apache.jena.atlas.web.TypedInputStream tin) static org.apache.jena.graph.GraphreadAsGiven(org.apache.jena.graph.Graph graph, String uri) static org.apache.jena.query.DatasetreadAsGiven(org.apache.jena.query.Dataset dataset, InputStream in, org.apache.jena.riot.Lang lang) static org.apache.jena.query.DatasetreadAsGiven(org.apache.jena.query.Dataset dataset, String uri) static org.apache.jena.query.DatasetreadAsGiven(org.apache.jena.query.Dataset dataset, String uri, String baseIri) static org.apache.jena.rdf.model.ModelreadAsGiven(org.apache.jena.rdf.model.Model model, String uri) static org.apache.jena.sparql.core.DatasetGraphreadAsGiven(org.apache.jena.sparql.core.DatasetGraph datasetGraph, InputStream in, org.apache.jena.riot.Lang lang) static org.apache.jena.sparql.core.DatasetGraphreadAsGiven(org.apache.jena.sparql.core.DatasetGraph datasetGraph, String uri) static org.apache.jena.sparql.core.DatasetGraphreadAsGiven(org.apache.jena.sparql.core.DatasetGraph datasetGraph, String uri, String baseIri) static voidstatic StringtoString(org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat) static StringtoString(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat) static org.apache.jena.atlas.web.TypedInputStreamwrapInputStream(InputStream in, org.apache.jena.atlas.web.TypedInputStream proto) Wrap an InputStream as a TypedInputStream based on the attributes of the latterstatic voidwriteAsGiven(OutputStream out, org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri) static voidwriteAsGiven(OutputStream out, org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri) static voidwriteAsGiven(OutputStream out, org.apache.jena.sparql.core.DatasetGraph datasetGraph, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri)
-
Field Details
-
DEFAULT_PROBE_LANGS
-
-
Constructor Details
-
RDFDataMgrEx
public RDFDataMgrEx()
-
-
Method Details
-
toString
public static String toString(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat) -
toString
public static String toString(org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat) -
isStdIn
-
getLang
public static org.apache.jena.riot.Lang getLang(org.apache.jena.atlas.web.TypedInputStream tin) Map a TypedInputStream's media type to a Lang- Parameters:
tin-- Returns:
-
read
public static void read(org.apache.jena.rdf.model.Model model, org.apache.jena.atlas.web.TypedInputStream tin) -
forceBuffered
public static org.apache.jena.atlas.web.TypedInputStream forceBuffered(org.apache.jena.atlas.web.TypedInputStream tin) Return a TypedInputStream whose underlying InputStream supports marks If the original one already supports it it is returned as is.- Parameters:
tin-- Returns:
-
forceBuffered
-
wrapInputStream
public static org.apache.jena.atlas.web.TypedInputStream wrapInputStream(InputStream in, org.apache.jena.atlas.web.TypedInputStream proto) Wrap an InputStream as a TypedInputStream based on the attributes of the latter- Parameters:
in-proto-- Returns:
-
decode
public static InputStream decode(InputStream in, List<String> codecs) throws org.apache.commons.compress.compressors.CompressorException - Throws:
org.apache.commons.compress.compressors.CompressorException
-
decode
public static InputStream decode(InputStream in, List<String> codecs, org.apache.commons.compress.compressors.CompressorStreamFactory csf) throws org.apache.commons.compress.compressors.CompressorException Decode a given input stream based on a sequence of codec names.- Parameters:
in-codecs-csf-- Returns:
- Throws:
org.apache.commons.compress.compressors.CompressorException
-
encode
public static OutputStream encode(OutputStream out, List<String> codecs, org.apache.commons.compress.compressors.CompressorStreamFactory csf) throws org.apache.commons.compress.compressors.CompressorException - Throws:
org.apache.commons.compress.compressors.CompressorException
-
encoder
-
encoder
-
encoder
public static Function<OutputStream,OutputStream> encoder(org.apache.commons.compress.compressors.CompressorStreamFactory csf, List<String> codecs) -
probeEncodings
public static InputStream probeEncodings(InputStream is, List<String> outEncodings) throws IOException Given an input stream with mark support, attempt to create a decoded input stream. The returned stream will be ready for further use with all detected encodings added to outEncodings.- Parameters:
is- An input stream that must have mark supportoutEncodings- Output argument. Detected encodings will be added to that list (if not null).- Throws:
IOException
-
probeEntityInfo
public static RdfEntityInfo probeEntityInfo(Callable<InputStream> inSupp, Iterable<org.apache.jena.riot.Lang> candidates) throws IOException Probe an input stream for any encodings (e.g. using compression codecs) and its eventual content type.try (InputStream in = ...) { EntityInfo entityInfo = probeEntityInfo(in, RDFDataMgrEx.DEFAULT_PROBE_LANGS); }- Parameters:
in-candidates-- Returns:
- Throws:
IOException
-
probeEntityInfo
public static RdfEntityInfo probeEntityInfo(Path path, Iterable<org.apache.jena.riot.Lang> candidates) throws IOException - Throws:
IOException
-
probeEntityInfo
public static RdfEntityInfo probeEntityInfo(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates) throws IOException This method closes the input stream when it returns.- Throws:
IOException
-
probeLang
public static org.apache.jena.atlas.web.TypedInputStream probeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) -
probeLang
public static org.apache.jena.atlas.web.TypedInputStream probeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates) Determine the RDF content of the given input stream. The returned input stream buffers the given stream if needed. Only the returned stream should be used after using this function. The following example shows how to obtain a Lang from the probing result:TypedInputStream tin = RDFDataMgrEx.probeLang(in, RDFDataMgrEx.DEFAULT_PROBE_LANGS); Lang lang = RDFLanguages.contentTypeToLang(tis.getContentType());
-
setDefaultMark
-
probeLang
public static org.apache.jena.atlas.web.TypedInputStream probeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, boolean tryAllCandidates, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) Probe the content of the input stream against a given set of candidate languages. Wraps the input stream as a BufferedInputStream and can thus also probe on STDIN. This is also the reason why the method does not take an InputStream supplier as argument. The result is a TypedInputStream which combines the BufferedInputStream with content type information- Parameters:
in-candidates-tryAllCandidates- If true do not accept the first successful candidate; instead try all candidates and pick the one that yields most data- Returns:
-
probeLang
public static org.apache.jena.atlas.web.TypedInputStream probeLang(InputStream in, Iterable<org.apache.jena.riot.Lang> candidates, boolean tryAllCandidates) -
peek
-
open
public static org.apache.jena.atlas.web.TypedInputStream open(String src, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) Attempts to open the given src and probe for the content type Src may be '-' but not NULL in order to refer to STDIN.- Parameters:
src-probeLangs-- Returns:
-
open
-
open
public static org.apache.jena.atlas.web.TypedInputStream open(Path path, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) open via nio -
open
-
probeForSpecificLang
public static org.apache.jena.atlas.web.TypedInputStream probeForSpecificLang(org.apache.jena.atlas.web.TypedInputStream result, Iterable<org.apache.jena.riot.Lang> probeLangs, Collection<Map.Entry<org.apache.jena.riot.Lang, Throwable>> errorCollector) -
newParserBuilderForReadAsGiven
Return a preconfigured parser builder that retains blank node ids and relative IRIs -
readAsGiven
public static org.apache.jena.graph.Graph readAsGiven(org.apache.jena.graph.Graph graph, String uri) -
readAsGiven
public static org.apache.jena.rdf.model.Model readAsGiven(org.apache.jena.rdf.model.Model model, String uri) -
readAsGiven
public static org.apache.jena.sparql.core.DatasetGraph readAsGiven(org.apache.jena.sparql.core.DatasetGraph datasetGraph, String uri) -
readAsGiven
public static org.apache.jena.query.Dataset readAsGiven(org.apache.jena.query.Dataset dataset, String uri) -
loadModelAsGiven
-
readAsGiven
-
readAsGiven
-
readAsGiven
public static org.apache.jena.sparql.core.DatasetGraph readAsGiven(org.apache.jena.sparql.core.DatasetGraph datasetGraph, InputStream in, org.apache.jena.riot.Lang lang) -
readAsGiven
public static org.apache.jena.query.Dataset readAsGiven(org.apache.jena.query.Dataset dataset, InputStream in, org.apache.jena.riot.Lang lang) -
loadDatasetAsGiven
-
writeAsGiven
public static void writeAsGiven(OutputStream out, org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri) -
writeAsGiven
public static void writeAsGiven(OutputStream out, org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri) -
writeAsGiven
public static void writeAsGiven(OutputStream out, org.apache.jena.sparql.core.DatasetGraph datasetGraph, org.apache.jena.riot.RDFFormat rdfFormat, String baseIri) -
printParseRoundtrip
public static org.apache.jena.query.Dataset printParseRoundtrip(org.apache.jena.query.Dataset dataset, org.apache.jena.riot.RDFFormat rdfFormat, org.apache.jena.query.Dataset result) Serialize a dataset in memory and return its deserialized version.- Parameters:
dataset- The input dataset.rdfFormat- The serialization format. Its lang is used for deserialization.result- The dataset to write to. If null then a new default dataset is created.- Returns:
- The dataset obtained from deserialization.
-
printParseRoundtrip
public static org.apache.jena.rdf.model.Model printParseRoundtrip(org.apache.jena.rdf.model.Model model, org.apache.jena.riot.RDFFormat rdfFormat, org.apache.jena.rdf.model.Model result) Serialize a model in memory and return its deserialized version.- Parameters:
model- The input model.rdfFormat- The serialization format. Its lang is used for deserialization.result- The model to write to. If null then a new default model is created.- Returns:
- The model obtained from deserialization.
-