这个想法是写Java
OutputStream并将其通过管道传递给Java
InputStream。可能的实现如下所示:
public static Model getModel(final OWLontology ontology) { Model model = ModelFactory.createDefaultModel(); try (PipedInputStream is = new PipedInputStream(); PipedOutputStream os = new PipedOutputStream(is)) { new Thread(new Runnable() { @Override public void run() { try { ontology.getOWLontologyManager().saveontology(ontology, new TurtledocumentFormat(), os); os.close(); } catch (OWLontologyStorageException | IOException e) { e.printStackTrace(); } } }).start(); model.read(is, null, "TURTLE"); return model; } catch (Exception e) { throw new RuntimeException("Could not convert OWL API ontology to JENA API model.", e); }}
或者,您可以简单地使用
ByteArrayOutputStream和
ByteArrayInputStream代替管道流。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)