本文整理汇总了Java中org.apache.jena.rdf.model.Model.write方法的典型用法代码示例。如果您正苦于以下问题:Java Model.write方法的具体用法?Java Model.write怎么用?Java Model.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Model
的用法示例。
在下文中一共展示了Model.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.jena.rdf.model.Model; //导入方法依赖的package包/类
@Override
public RESTResource get(URI uri, Map<String, String> parameters) throws RESTException {
RESTResource resource = new RESTResource(uri.toString(),this);
Dataset dataset = ThingDirectory.get().dataset;
dataset.begin(ReadWrite.READ);
try {
Model result = dataset.getNamedModel(uri.toString());
if (!result.isEmpty()) {
resource.contentType = "text/turtle";
ByteArrayOutputStream out = new ByteArrayOutputStream();
result.write(out, "Turtle");
resource.content = out.toString();
} else {
throw new RESTException();
}
} finally {
dataset.end();
}
return resource;
}
示例2: main
import org.apache.jena.rdf.model.Model; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
PropertyConfigurator.configure("log4j.info");
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
FileOutputStream out = new FileOutputStream(new File("/usr/local/RAID/geonames.nt"));
String buffer = null;
int count = 0;
while ((buffer = reader.readLine()) != null) {
if (++count % 2 == 0) {
logger.debug("processing xml: " + buffer);
Model model = ModelFactory.createDefaultModel() ;
model.read(new StringReader(buffer), null, "RDF/XML");
model.write(out, "N-TRIPLE");
} else {
logger.info("skipping: " + buffer);
}
}
reader.close();
}
示例3: writeToDisk
import org.apache.jena.rdf.model.Model; //导入方法依赖的package包/类
private void writeToDisk(URI uri, Model model){
logger.debug("Writing model for " + uri + "to disk.");
File cacheFile = getCacheFile(uri);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(cacheFile))) {
model.write(os, cacheFileLanguage.getLabel());
} catch (IOException e) {
logger.error("Could not write to disk.", e);
}
}