use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class LocatorClassLoader method open.
@Override
public TypedInputStream open(String resourceName) {
if (classLoader == null)
return null;
InputStream in = classLoader.getResourceAsStream(resourceName);
if (in == null) {
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Failed to open: " + resourceName);
return null;
}
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Found: " + resourceName);
ContentType ct = RDFLanguages.guessContentType(resourceName);
// No sensible base URI.
return new TypedInputStream(in, ct, null);
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class LocatorFile method open.
/** Open anything that looks a bit like a file name */
@Override
public TypedInputStream open(String filenameIRI) {
String fn = toFileName(filenameIRI);
if (fn == null)
return null;
try {
if (!exists$(fn)) {
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Not found: " + filenameIRI + thisDirLogStr);
return null;
}
} catch (AccessControlException e) {
log.warn("Security problem testing for file", e);
return null;
}
try {
InputStream in = IO.openFileEx(fn);
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Found: " + filenameIRI + thisDirLogStr);
ContentType ct = RDFLanguages.guessContentType(filenameIRI);
return new TypedInputStream(in, ct, filenameIRI);
} catch (IOException ioEx) {
// Includes FileNotFoundException
// We already tested whether the file exists or not.
log.warn("File unreadable (but exists): " + fn + " Exception: " + ioEx.getMessage());
return null;
}
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class AdapterFileManager method readModelWorker.
// -------- Cache operations (end)
@Override
protected Model readModelWorker(Model model, String filenameOrURI, String baseURI, String syntax) {
// Doesn't call open() - we want to make the syntax guess
// based on the mapped URI.
String mappedURI = mapURI(filenameOrURI);
if (log.isDebugEnabled() && !mappedURI.equals(filenameOrURI))
log.debug("Map: " + filenameOrURI + " => " + mappedURI);
Lang lang = (syntax != null) ? RDFLanguages.nameToLang(syntax) : RDFLanguages.resourceNameToLang(mappedURI, Lang.RDFXML);
// Allow model.read to be overridden e.g. by OntModel which does import processing.
if (baseURI == null)
baseURI = SysRIOT.chooseBaseIRI(filenameOrURI);
try (TypedInputStream in = streamManager.openNoMapOrNull(mappedURI)) {
Lang lang2 = RDFDataMgr.determineLang(mappedURI, in.getContentType(), lang);
// May be overridden by model implementation.
model.read(in, baseURI, lang2.getName());
}
return model;
}
use of org.apache.jena.atlas.web.TypedInputStream 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.TypedInputStream 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;
}
Aggregations