Search in sources :

Example 11 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)

Example 12 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 = new FileManager();
    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) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 13 with NotFoundException

use of org.apache.jena.shared.NotFoundException in project jena by apache.

the class TestFileManager method testLocationMappingURLtoFileOpenNotFound.

@Test
public void testLocationMappingURLtoFileOpenNotFound() {
    LocationMapper locMap = new LocationMapper(TestLocationMapper.mapping);
    FileManager fileManager = new FileManager(locMap);
    fileManager.addLocatorClassLoader(fileManager.getClass().getClassLoader());
    try {
        InputStream in = fileManager.open("http://example.org/file");
        closeInputStream(in);
        assertNull("Found nont-existant URL", null);
    } catch (NotFoundException ex) {
    }
}
Also used : InputStream(java.io.InputStream) NotFoundException(org.apache.jena.shared.NotFoundException) LocationMapper(org.apache.jena.util.LocationMapper) TestLocationMapper(org.apache.jena.riot.stream.TestLocationMapper) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 14 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 FileManager();
    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)

Example 15 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 FileManager();
    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) FileManager(org.apache.jena.util.FileManager)

Aggregations

NotFoundException (org.apache.jena.shared.NotFoundException)15 InputStream (java.io.InputStream)12 FileManager (org.apache.jena.util.FileManager)10 BaseTest (org.apache.jena.atlas.junit.BaseTest)5 Test (org.junit.Test)5 TerminationException (jena.cmd.TerminationException)2 LocationMapper (org.apache.jena.util.LocationMapper)2 ResultSet (org.apache.jena.query.ResultSet)1 Model (org.apache.jena.rdf.model.Model)1 TestLocationMapper (org.apache.jena.riot.stream.TestLocationMapper)1 SDBException (org.apache.jena.sdb.SDBException)1 ARQException (org.apache.jena.sparql.ARQException)1 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)1