/** * Utility to load a file into a model a Model. Files are assumed to be relative to the BASE_URI. * * @param file the file name, relative to baseDir * @return the loaded Model */ public static Model loadFile(String file, Model model) throws IOException { String langType = "RDF/XML"; if (file.endsWith(".nt")) { langType = "N-TRIPLE"; } else if (file.endsWith("n3")) { langType = "N3"; } String fname = file; if (fname.startsWith(BASE_URI)) { fname = fname.substring(BASE_URI.length()); } Reader reader = new BufferedReader(new FileReader(BASE_TESTDIR + fname)); model.read(reader, BASE_URI + fname, langType); return model; }
/** Load all of the known manifest files into a single model */ public static Model loadAllTestDefinitions() { System.out.print("Loading manifests "); System.out.flush(); Model testDefs = ModelFactory.createDefaultModel(); int count = 0; for (String TEST_DIR : TEST_DIRS) { File dir = new File(BASE_TESTDIR + TEST_DIR); String[] manifests = dir.list( new FilenameFilter() { @Override public boolean accept(File df, String name) { if (name.startsWith("Manifest") && name.endsWith(".rdf")) { return includeModified || !name.endsWith("-mod.rdf"); } else { return false; } } }); for (String manifest : manifests) { File mf = new File(dir, manifest); try { testDefs.read(new FileInputStream(mf), "file:" + mf); count++; if (count % 8 == 0) { System.out.print("."); System.out.flush(); } } catch (FileNotFoundException e) { System.out.println("File not readable - " + e); } } } System.out.println("loaded"); return testDefs; }