use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class TestFileManager method testFileManagerLocatorClassLoaderNotFound.
@Test
public void testFileManagerLocatorClassLoaderNotFound() {
FileManager fileManager = FileManager.create();
fileManager.addLocatorClassLoader(fileManager.getClass().getClassLoader());
try {
InputStream in = fileManager.open("not/java/lang/String.class");
closeInputStream(in);
assertNull("Found non-existant class", in);
} catch (NotFoundException ex) {
}
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class TestFileManager method testFileManagerNoFile.
public void testFileManagerNoFile() {
FileManager fileManager = new FileManagerImpl();
fileManager.addLocatorFile();
try {
// Tests either way round - exception or a null return.
InputStream in = fileManager.open(filenameNonExistent);
closeInputStream(in);
assertNull("Found non-existant file: " + filenameNonExistent, in);
} catch (NotFoundException ex) {
}
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class TestFileManager method testFileManagerLocatorClassLoaderNotFound.
public void testFileManagerLocatorClassLoaderNotFound() {
FileManager fileManager = new FileManagerImpl();
fileManager.addLocatorClassLoader(fileManager.getClass().getClassLoader());
try {
InputStream in = fileManager.open("not/java/lang/String.class");
closeInputStream(in);
assertNull("Found non-existant class", in);
} catch (NotFoundException ex) {
}
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class ReadAnything method read.
/**
* Read something RDF/SPARQL like
*/
public static SPARQLResult read(String url, Context context) {
Objects.requireNonNull(url);
TypedInputStream in = StreamManager.get(context).open(url);
if (in == null)
throw new NotFoundException(url);
ContentType ct = WebContent.determineCT(in.getContentType(), null, url);
Lang lang = RDFLanguages.contentTypeToLang(ct);
if (RDFLanguages.isTriples(lang)) {
Model model = ModelFactory.createDefaultModel();
Supplier<SPARQLResult> r = () -> {
StreamRDF sink = StreamRDFLib.graph(model.getGraph());
RDFParser.source(in).lang(lang).parse(sink);
return new SPARQLResult(model);
};
if (model.supportsTransactions())
return model.calculateInTxn(r);
else
return r.get();
}
if (RDFLanguages.isQuads(lang)) {
Dataset ds = DatasetFactory.create();
Supplier<SPARQLResult> r = () -> {
StreamRDF sink = StreamRDFLib.dataset(ds.asDatasetGraph());
RDFParser.source(in).lang(lang).parse(sink);
return new SPARQLResult(ds);
};
if (ds.supportsTransactions())
return Txn.calculateWrite(ds, r);
else
return r.get();
}
if (ResultSetReaderRegistry.isRegistered(lang)) {
return ResultsReader.create().forceLang(lang).context(context).build().readAny(in.getInputStream());
// Which would do, if we need to invert the code ...
// ResultSetReaderFactory factory = ResultSetReaderRegistry.getFactory(lang);
// if ( factory == null )
// throw new RiotException("No ResultSetReaderFactory for "+lang);
// ResultSetReader reader = factory.create(lang);
// ResultSet rs = reader.read(in.getInputStream(), context);
}
throw new RiotException("Failed to determine: lang = " + lang);
}
use of org.apache.jena.shared.NotFoundException in project jena by apache.
the class SSE method readFile.
/**
* Read a file and obtain an SSE item expression
*/
public static Item readFile(String filename, PrefixMapping pmap) {
FileInputStream in = null;
try {
in = new FileInputStream(filename);
long len = in.getChannel().size();
if (len == 0)
return Item.nil;
return parse(in, pmap);
} catch (FileNotFoundException ex) {
throw new NotFoundException("Not found: " + filename);
} catch (IOException ex) {
throw new ARQException("IOExeption: " + filename, ex);
} finally {
IO.close(in);
}
}
Aggregations