本文整理汇总了Java中org.apache.jena.util.FileUtils类的典型用法代码示例。如果您正苦于以下问题:Java FileUtils类的具体用法?Java FileUtils怎么用?Java FileUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileUtils类属于org.apache.jena.util包,在下文中一共展示了FileUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fs_write_01
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
@Test
public void fs_write_01() throws IOException {
FileStore fs = FileStore.attach(STORE, "FILE");
assertEquals(0, fs.getCurrentIndex());
FileEntry entry = fs.writeNewFile(out->{
try(AWriter aw = IO .wrapUTF8(out)) {
aw.write("abc");
}
}) ;
assertNotNull(entry);
assertNotNull(entry.datafile);
int idx = checkFilename(entry.datafile);
assertEquals(1, idx);
// Read it back in again.
String s = FileUtils.readWholeFileAsUTF8(entry.getDatafileName());
assertEquals("abc", s);
}
示例2: AbstractTool
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
AbstractTool() {
InputStream shaclTTL = SHACLSystemModel.class.getResourceAsStream("/etc/shacl.ttl");
Model shacl = JenaUtil.createMemoryModel();
shacl.read(shaclTTL, SH.BASE_URI, FileUtils.langTurtle);
shacl.add(SystemTriples.getVocabularyModel());
dm.addModel(SH.BASE_URI, shacl);
InputStream dashTTL = SHACLSystemModel.class.getResourceAsStream("/etc/dash.ttl");
Model dash = JenaUtil.createMemoryModel();
dash.read(dashTTL, SH.BASE_URI, FileUtils.langTurtle);
dm.addModel(DASH.BASE_URI, dash);
InputStream toshTTL = SHACLSystemModel.class.getResourceAsStream("/etc/tosh.ttl");
Model tosh = JenaUtil.createMemoryModel();
tosh.read(toshTTL, SH.BASE_URI, FileUtils.langTurtle);
dm.addModel(TOSH.BASE_URI, tosh);
spec.setDocumentManager(dm);
}
示例3: getSHACLModel
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public static Model getSHACLModel() {
if(shaclModel == null) {
shaclModel = JenaUtil.createDefaultModel();
InputStream shaclTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/shacl.ttl");
shaclModel.read(shaclTTL, SH.BASE_URI, FileUtils.langTurtle);
InputStream dashTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/dash.ttl");
shaclModel.read(dashTTL, SH.BASE_URI, FileUtils.langTurtle);
InputStream toshTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/tosh.ttl");
shaclModel.read(toshTTL, SH.BASE_URI, FileUtils.langTurtle);
shaclModel.add(SystemTriples.getVocabularyModel());
SHACLFunctions.registerFunctions(shaclModel);
}
return shaclModel;
}
示例4: collectTestCases
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
private static void collectTestCases(File folder, List<TestCase> testCases) throws Exception {
for(File f : folder.listFiles()) {
if(f.isDirectory()) {
collectTestCases(f, testCases);
}
else if(f.isFile() && f.getName().endsWith(".ttl")) {
Model testModel = JenaUtil.createDefaultModel();
InputStream is = new FileInputStream(f);
testModel.read(is, "urn:dummy", FileUtils.langTurtle);
testModel.add(SHACLSystemModel.getSHACLModel());
Resource ontology = testModel.listStatements(null, OWL.imports, ResourceFactory.createResource(DASH.BASE_URI)).next().getSubject();
for(TestCaseType type : TestCaseTypes.getTypes()) {
testCases.addAll(type.getTestCases(testModel, ontology));
}
}
}
}
示例5: getSHACLModel
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public static Model getSHACLModel() {
if(shaclModel == null) {
shaclModel = JenaUtil.createDefaultModel();
InputStream shaclTTL = SHACLSystemModel.class.getResourceAsStream("/etc/shacl.ttl");
shaclModel.read(shaclTTL, SH.BASE_URI, FileUtils.langTurtle);
InputStream dashTTL = SHACLSystemModel.class.getResourceAsStream("/etc/dash.ttl");
shaclModel.read(dashTTL, SH.BASE_URI, FileUtils.langTurtle);
InputStream toshTTL = SHACLSystemModel.class.getResourceAsStream("/etc/tosh.ttl");
shaclModel.read(toshTTL, SH.BASE_URI, FileUtils.langTurtle);
shaclModel.add(SystemTriples.getVocabularyModel());
SHACLFunctions.registerFunctions(shaclModel);
}
return shaclModel;
}
示例6: mainTDB
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public static void mainTDB(String...argv) throws IOException {
DatasetGraphTDB dsg = ((DatasetGraphTransaction)TDBFactory.createDatasetGraph()).get() ;
String DIR = "testing/Inf" ;
String DATA_FILE = DIR+"/rdfs-data.ttl" ;
String VOCAB_FILE = DIR+"/rdfs-vocab.ttl" ;
String RULES_FILE = DIR+"/rdfs-min.rules" ;
Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
Model data = RDFDataMgr.loadModel(DATA_FILE) ;
String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
rules = rules.replaceAll("#[^\\n]*", "") ;
// TDB
InferenceSetupRDFS_TDB setup = new InferenceSetupRDFS_TDB(vocab, dsg, false) ;
//Graph graph = new GraphRDFS(setup, data.getGraph()) ;
}
示例7: expand
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public static void expand() throws IOException {
boolean combined = false ;
String DIR = "testing/Inf" ;
String DATA_FILE = "data.ttl" ;
String VOCAB_FILE = "vocab.ttl" ;
String RULES_FILE = DIR+"/rdfs-min.rules" ;
Model vocab = RDFDataMgr.loadModel(VOCAB_FILE) ;
Model data = RDFDataMgr.loadModel(DATA_FILE) ;
String rules = FileUtils.readWholeFileAsUTF8(RULES_FILE) ;
rules = rules.replaceAll("#[^\\n]*", "") ;
InferenceSetupRDFS setup = new InferenceSetupRDFS(vocab, combined) ;
Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
InfModel m = ModelFactory.createInfModel(reasoner, vocab, data);
// Expansion Graph
Graph graphExpanded = Factory.createDefaultGraph() ;
StreamRDF stream = StreamRDFLib.graph(graphExpanded) ;
// Apply inferences.
stream = new InferenceProcessorStreamRDF(stream, setup) ;
sendToStream(data.getGraph(), stream) ;
RDFDataMgr.write(System.out, graphExpanded, Lang.TTL) ;
}
示例8: loadGraph
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public Model loadGraph(String path) {
// load model from static dump (can find an example in
// /cLODg/src/main/resources/data/all-names.rdf)
Model m = ModelFactory.createDefaultModel();
InputStream is = null;
String syntax = null;
if (path == null) {
is = getClass().getClassLoader().getResourceAsStream(GRAPH_NAME);
syntax = "RDF/XML";
} else {
try {
is = new FileInputStream(new File(path));
syntax = FileUtils.guessLang(path);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
if (is != null)
m.read(is, null, syntax);
return m;
}
示例9: getBodyModel
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
public Model getBodyModel(HttpHeaders hh, InputStream body, boolean isPOST) {
MediaType mediaType = hh.getMediaType();
if (mediaType == null) return null;
String mime = mediaType.getType() + "/" + mediaType.getSubtype(); // ignore parameters
if (mime.equals(JSONLDSupport.MIME_JSONLD)) {
return JSONLDSupport.readModel(baseURI(isPOST), body);
} else if (mime.equals(RDFCSVUtil.MEDIA_TYPE)) {
return CSVPayloadRead.readCSVStream(body, baseURI(isPOST));
} else {
String lang = null;
if ( MIME_RDFXML.equals( mime ) ) {
lang = FileUtils.langXML;
} else if ( MIME_TURTLE.equals( mime ) ) {
lang = FileUtils.langTurtle;
} else {
return null;
}
Model m = ModelFactory.createDefaultModel();
m.read(body, baseURI(isPOST), lang);
return m;
}
}
示例10: logAction
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
protected void logAction(String action, String graph, Model data) {
if (logDirectory != null) {
String dir = logDirectory + File.separator + NameUtils.encodeSafeName(graph);
FileUtil.ensureDir(dir);
String filename = String.format("on-%s-%s.ttl", System.currentTimeMillis(), action);
File logFile = new File(dir, filename);
try {
if (data != null) {
OutputStream out = new FileOutputStream(logFile);
data.write(out, FileUtils.langTurtle);
out.close();
} else {
logFile.createNewFile();
}
} catch (IOException e) {
log.error("Failed to create log file: " + logFile);
}
}
}
示例11: testBNodeSubmitter
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
@Test
public void testBNodeSubmitter() {
addEntry("file:test/reg1.ttl", ROOT_REGISTER);
Register parent = store.getCurrentVersion(REG1).asRegister();
String base = NameUtils.ensureLastSlash(REG1);
Model m = ModelFactory.createDefaultModel();
m.read("file:test/red-submitter-test.ttl", base, FileUtils.langTurtle);
Calendar now = Calendar.getInstance();
for (ResIterator i = m.listResourcesWithProperty(RDF.type, RegistryVocab.RegisterItem); i.hasNext();) {
RegisterItem item = RegisterItem.fromRIRequest(i.next(), REG1, true, now);
store.addToRegister(parent, item);
}
RegisterItem ri = store.getItem(REG1 + "/_red", true);
List<Statement> submitters = ri.getRoot().listProperties(RegistryVocab.submitter).toList();
assertEquals(1, submitters.size());
ri.getEntity().addProperty(RDFS.comment, "Updated");
store.update(ri, true);
ri = store.getItem(REG1 + "/_red", true);
submitters = ri.getRoot().listProperties(RegistryVocab.submitter).toList();
assertEquals(1, submitters.size());
}
示例12: toFileName
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
/**
* Processing the filename for file: or relative filename and return a
* filename suitable for file operations.
*/
public String toFileName(String filenameIRI) {
// Do not use directly : it will ignore the directory.
//IRILib.filenameToIRI
String scheme = FileUtils.getScheme(filenameIRI);
String fn = filenameIRI;
// Windows : C:\\ is not a scheme name!
if (scheme != null) {
if (scheme.length() == 1) {
// Not perfect for MS Windows but if thisDir is set then
// the main use case is resolving relative (no drive)
// filenames against thisDir. Treat the presence of a
// drive letter as making this a JVM relative filename.
return fn;
} else if (scheme.length() > 1) {
if (!scheme.equalsIgnoreCase("file")) // Not file: IRI
{
return null;
}
fn = IRILib.IRIToFilename(filenameIRI);
// fall through
}
}
// fn is the file name to use.
return absolute(fn);
}
示例13: parseGraph
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
private Graph parseGraph(RDFNode node) {
Model model = JenaUtil.createDefaultModel();
if(node.isLiteral()) {
String str = node.asLiteral().getLexicalForm();
model.read(new ByteArrayInputStream(str.getBytes()), "urn:x-dummy", FileUtils.langTurtle);
}
return model.getGraph();
}
示例14: collectItems
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
private void collectItems(File manifestFile, String baseURI) throws IOException {
String filePath = manifestFile.getAbsolutePath().replaceAll("\\\\", "/");
int coreIndex = filePath.indexOf("core/");
if(coreIndex > 0 && !filePath.contains("sparql/core")) {
filePath = filePath.substring(coreIndex);
}
else {
int sindex = filePath.indexOf("sparql/");
if(sindex > 0) {
filePath = filePath.substring(sindex);
}
}
Model model = JenaUtil.createMemoryModel();
model.read(new FileInputStream(manifestFile), baseURI, FileUtils.langTurtle);
for(Resource manifest : model.listSubjectsWithProperty(RDF.type, MF.Manifest).toList()) {
for(Resource include : JenaUtil.getResourceProperties(manifest, MF.include)) {
String path = include.getURI().substring(baseURI.length());
File includeFile = new File(manifestFile.getParentFile(), path);
if(path.contains("/")) {
String addURI = path.substring(0, path.indexOf('/'));
collectItems(includeFile, baseURI + addURI + "/");
}
else {
collectItems(includeFile, baseURI + path);
}
}
for(Resource entries : JenaUtil.getResourceProperties(manifest, MF.entries)) {
for(RDFNode entry : entries.as(RDFList.class).iterator().toList()) {
items.add(new Item(entry.asResource(), filePath, manifestFile));
}
}
}
}
示例15: getDataModel
import org.apache.jena.util.FileUtils; //导入依赖的package包/类
protected Model getDataModel(String[] args) throws IOException {
for(int i = 0; i < args.length - 1; i++) {
if(DATA_FILE.equals(args[i])) {
String dataFileName = args[i + 1];
OntModel dataModel = ModelFactory.createOntologyModel(spec);
File dataFile = new File(dataFileName);
dataModel.read(new FileInputStream(dataFile), "urn:x-base", FileUtils.langTurtle);
return dataModel;
}
}
System.err.println("Missing -datafile, e.g.: -datafile myfile.ttl");
System.exit(0);
return null;
}