use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class TestStreamManager method open.
// TriG
// NQuads
private static void open(StreamManager streamMgr, String dataName, Context context) {
StreamManager.setGlobal(streamMgr);
try {
TypedInputStream in = (context != null) ? RDFDataMgr.open(dataName, context) : RDFDataMgr.open(dataName);
assertNotNull(in);
IO.close(in);
} finally {
StreamManager.setGlobal(streamMgrStd);
}
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class JenaIOEnvironment method createLocationMapper.
/** Search a path (which is delimited by ";" because ":" is used in URIs)
* to find a description of a LocationMapper, then create and return a
* LocationMapper based on the description.
*/
public static LocationMapper createLocationMapper(String configPath) {
if (configPath == null || configPath.length() == 0) {
log.warn("Null configuration");
return null;
}
// Make a file manager to look for the location mapping file
StreamManager smgr = new StreamManager();
smgr.addLocator(new LocatorFile());
smgr.addLocator(new LocatorClassLoader(smgr.getClass().getClassLoader()));
try {
String uriConfig = null;
TypedInputStream in = null;
StringTokenizer pathElems = new StringTokenizer(configPath, AdapterFileManager.PATH_DELIMITER);
while (pathElems.hasMoreTokens()) {
String uri = pathElems.nextToken();
if (uri == null || uri.length() == 0)
break;
in = smgr.openNoMapOrNull(uri);
if (in != null) {
uriConfig = uri;
break;
}
}
if (in == null) {
log.debug("Failed to find configuration: " + configPath);
return null;
}
String syntax = FileUtils.guessLang(uriConfig);
Model model = ModelFactory.createDefaultModel();
model.read(in, uriConfig, syntax);
return processConfig(model);
} catch (JenaException ex) {
LoggerFactory.getLogger(LocationMapper.class).warn("Error in configuration file: " + ex.getMessage());
return new LocationMapper();
}
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class LocatorFTP method performOpen.
@Override
public TypedInputStream performOpen(String uri) {
if (uri.startsWith("ftp://")) {
try {
URL url = new URL(uri);
InputStream in = url.openStream();
ContentType ct = RDFLanguages.guessContentType(uri);
return new TypedInputStream(in, ct);
} catch (MalformedURLException ex) {
throw new RiotException("Bad FTP URL: " + uri, ex);
} catch (IOException ex) {
// This includes variations on "not found"
IO.exception(ex);
}
}
return null;
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class LocatorZip method open.
@Override
public TypedInputStream open(String filenameOrURI) {
ZipEntry entry = zipFile.getEntry(filenameOrURI);
if (entry == null) {
if (StreamManager.logAllLookups && log.isDebugEnabled())
log.debug("Not found: " + zipFileName + " : " + filenameOrURI);
return null;
}
try {
InputStream in = zipFile.getInputStream(entry);
if (in == null) {
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Not found: " + filenameOrURI);
return null;
}
if (StreamManager.logAllLookups && log.isTraceEnabled())
log.trace("Found: " + filenameOrURI);
ContentType ct = RDFLanguages.guessContentType(filenameOrURI);
return new TypedInputStream(in, ct, filenameOrURI);
} catch (IOException ex) {
log.warn("IO Exception opening zip entry: " + filenameOrURI);
return null;
}
}
use of org.apache.jena.atlas.web.TypedInputStream in project jena by apache.
the class TestLocators method locatorFile_05.
@Test
public void locatorFile_05() {
LocatorFile loc = new LocatorFile();
TypedInputStream ts = loc.open(testingDir + "data.ttl");
assertTrue("Not equal: " + WebContent.contentTypeTurtle + " != " + ts.getMediaType(), WebContent.contentTypeTurtle.equalsIgnoreCase(ts.getContentType()));
}
Aggregations