Search in sources :

Example 31 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testLocationMappingURLtoFileOpen.

public void testLocationMappingURLtoFileOpen() {
    LocationMapper locMap = new LocationMapper(TestLocationMapper.mapping);
    FileManager fileManager = new FileManager(locMap);
    fileManager.addLocatorFile();
    InputStream in = fileManager.open("http://example.org/file");
    assertNotNull(in);
    closeInputStream(in);
}
Also used : InputStream(java.io.InputStream) LocationMapper(org.apache.jena.util.LocationMapper) FileManager(org.apache.jena.util.FileManager)

Example 32 with FileManager

use of org.apache.jena.util.FileManager 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 33 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testCache3.

public void testCache3() {
    FileManager fileManager = FileManager.get();
    fileManager.addLocatorFile(testingDir);
    fileManager.setModelCaching(true);
    Model m1 = fileManager.loadModel(fileModel);
    Model m2 = fileManager.loadModel(fileModel);
    assertSame(m1, m2);
    fileManager.removeCacheModel(fileModel);
    Model m3 = fileManager.loadModel(fileModel);
    assertNotSame(m1, m3);
    fileManager.resetCache();
    Model m4 = fileManager.loadModel(fileModel);
    Model m5 = fileManager.loadModel(fileModel);
    assertSame(m4, m5);
    assertNotSame(m1, m4);
    assertNotSame(m3, m4);
}
Also used : Model(org.apache.jena.rdf.model.Model) FileManager(org.apache.jena.util.FileManager)

Example 34 with FileManager

use of org.apache.jena.util.FileManager in project jena by apache.

the class TestFileManager method testFileManagerFileLocator.

public void testFileManagerFileLocator() {
    FileManager fileManager = new FileManager();
    fileManager.addLocatorFile();
    InputStream in = fileManager.open(testingDir + "/" + filename);
    assertNotNull(in);
    closeInputStream(in);
}
Also used : InputStream(java.io.InputStream) FileManager(org.apache.jena.util.FileManager)

Example 35 with FileManager

use of org.apache.jena.util.FileManager 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

FileManager (org.apache.jena.util.FileManager)35 InputStream (java.io.InputStream)21 BaseTest (org.apache.jena.atlas.junit.BaseTest)13 Test (org.junit.Test)13 Model (org.apache.jena.rdf.model.Model)12 NotFoundException (org.apache.jena.shared.NotFoundException)12 LocationMapper (org.apache.jena.util.LocationMapper)4 OntModel (org.apache.jena.ontology.OntModel)3 TestLocationMapper (org.apache.jena.riot.stream.TestLocationMapper)2 File (java.io.File)1 DocumentManagerAssembler (org.apache.jena.assembler.assemblers.DocumentManagerAssembler)1 JenaException (org.apache.jena.shared.JenaException)1