Search in sources :

Example 16 with NotFoundException

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) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test)

Example 17 with NotFoundException

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) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 18 with NotFoundException

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) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 19 with NotFoundException

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);
}
Also used : ContentType(org.apache.jena.atlas.web.ContentType) StreamRDF(org.apache.jena.riot.system.StreamRDF) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) NotFoundException(org.apache.jena.shared.NotFoundException) SPARQLResult(org.apache.jena.sparql.resultset.SPARQLResult) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 20 with NotFoundException

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);
    }
}
Also used : ARQException(org.apache.jena.sparql.ARQException) NotFoundException(org.apache.jena.shared.NotFoundException)

Aggregations

NotFoundException (org.apache.jena.shared.NotFoundException)22 InputStream (java.io.InputStream)15 FileManager (org.apache.jena.util.FileManager)5 Test (org.junit.Test)5 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)2 Model (org.apache.jena.rdf.model.Model)2 StreamRDF (org.apache.jena.riot.system.StreamRDF)2 FileNotFoundException (java.io.FileNotFoundException)1 BodyPublisher (java.net.http.HttpRequest.BodyPublisher)1 Path (java.nio.file.Path)1 TerminationException (jena.cmd.TerminationException)1 ContentType (org.apache.jena.atlas.web.ContentType)1 Dataset (org.apache.jena.query.Dataset)1 ResultSet (org.apache.jena.query.ResultSet)1 Lang (org.apache.jena.riot.Lang)1 RiotException (org.apache.jena.riot.RiotException)1 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)1 TestLocationMapper (org.apache.jena.riot.stream.TestLocationMapper)1