Search in sources :

Example 16 with FileManager

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

the class Env method initFM.

private static void initFM() {
    fileManager = new FileManager();
    fileManager.addLocatorFile();
    // sysBase = System.getenv(SDBROOT) ;
    if (sysBase == null)
        return;
    File baseDir = new File(sysBase);
    if (!baseDir.exists()) {
        log.warn("Directory does not exist: " + baseDir);
        return;
    }
    if (!baseDir.isDirectory()) {
        log.warn("Not a directory (but does exist): " + baseDir);
        return;
    }
    fileManager.addLocatorFile(sysBase);
}
Also used : File(java.io.File) FileManager(org.apache.jena.util.FileManager)

Example 17 with FileManager

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

the class OntDocumentManager method findMetadata.

/**
     * <p>
     * Search the given path for a resolvable URI, from which we load a model
     * (assuming RDF/XML).
     * </p>
     *
     * @param configPath The path to search
     * @return A model loaded by resolving an entry on the path, or null if
     * no path entries succeed.
     */
protected Model findMetadata(String configPath) {
    if (configPath == null) {
        return null;
    }
    // Make a temporary file manager to look for the metadata file
    FileManager fm = new FileManager();
    fm.addLocatorFile();
    fm.addLocatorURL();
    fm.addLocatorClassLoader(fm.getClass().getClassLoader());
    try {
        String uri = null;
        InputStream in = null;
        StringTokenizer pathElems = new StringTokenizer(configPath, FileManager.PATH_DELIMITER);
        while (in == null && pathElems.hasMoreTokens()) {
            uri = pathElems.nextToken();
            in = fm.openNoMap(uri);
        }
        if (in != null) {
            String syntax = FileUtils.guessLang(uri);
            Model model = ModelFactory.createDefaultModel();
            model.read(in, uri, syntax);
            m_policyURL = uri;
            return model;
        }
    } catch (JenaException e) {
        log.warn("Exception while reading configuration: " + e.getMessage(), e);
    }
    return null;
}
Also used : JenaException(org.apache.jena.shared.JenaException) InputStream(java.io.InputStream) FileManager(org.apache.jena.util.FileManager)

Example 18 with FileManager

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

the class TestFileManager method testFileManagerFileLocator.

@Test
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) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 19 with FileManager

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

the class TestFileManager method testCache1.

@Test
public void testCache1() {
    FileManager fileManager = new FileManager();
    fileManager.addLocatorFile(testingDir);
    Model m1 = fileManager.loadModel(fileModel);
    Model m2 = fileManager.loadModel(fileModel);
    assertNotSame(m1, m2);
}
Also used : OntModel(org.apache.jena.ontology.OntModel) Model(org.apache.jena.rdf.model.Model) FileManager(org.apache.jena.util.FileManager) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 20 with FileManager

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

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