Search in sources :

Example 6 with FileManager

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

the class TestFileManager method testFileManagerFileLocatorWithDir.

@Test
public void testFileManagerFileLocatorWithDir() {
    FileManager fileManager = new FileManager();
    fileManager.addLocatorFile(testingDir);
    InputStream in = fileManager.open(filename);
    assertNotNull(in);
    closeInputStream(in);
}
Also used : InputStream(java.io.InputStream) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 7 with FileManager

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

the class TestFileManager method testFileManagerClone.

@Test
public void testFileManagerClone() {
    FileManager fileManager1 = new FileManager();
    FileManager fileManager2 = fileManager1.clone();
    // Should not affect fileManager2
    fileManager1.addLocatorFile();
    {
        InputStream in = fileManager1.open(testingDir + "/" + filename);
        assertNotNull(in);
        closeInputStream(in);
    }
    // Should not work.
    try {
        InputStream in = fileManager2.open(testingDir + "/" + filename);
        closeInputStream(in);
        assertNull("Found file via wrong FileManager", 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 8 with FileManager

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

the class TestFileManager method testFileManagerLocatorZip.

@Test
public void testFileManagerLocatorZip() {
    FileManager fileManager = new FileManager();
    try {
        fileManager.addLocatorZip(zipname);
    } catch (Exception ex) {
        fail("Failed to create a filemanager and add a zip locator");
    }
    InputStream in = fileManager.open(filename);
    assertNotNull(in);
    closeInputStream(in);
}
Also used : InputStream(java.io.InputStream) FileManager(org.apache.jena.util.FileManager) NotFoundException(org.apache.jena.shared.NotFoundException) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 9 with FileManager

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

the class TestImportManager method testCacheModels.

public void testCacheModels() {
    ImportManager im = new ImportManager();
    Model spec = model("_x owl:imports M1");
    Model m1 = model("this isModel M1");
    FileManager withM1 = new FixedFileManager().add("eh:/M1", m1);
    Model A = im.withImports(withM1, spec);
    FileManager none = new FixedFileManager();
    Model B = im.withImports(none, spec);
    assertIsoModels(A, B);
}
Also used : Model(org.apache.jena.rdf.model.Model) FileManager(org.apache.jena.util.FileManager)

Example 10 with FileManager

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

the class TestFileManager method testLocationMappingURLtoFileOpenNotFound.

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