org.openrdf.rio.Rio.write()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.openrdf.rio.Rio.write方法的一些代码示例,展示了Rio.write的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Rio.write方法的具体详情如下:
包路径:org.openrdf.rio.Rio
类名称:Rio
方法名:write

Rio.write介绍

[英]Writes the given statements to the given OutputStream in the given format.

If the collection is a Model, its namespaces will also be written.
[中]将给定语句以给定格式写入给定的OutputStream。
如果集合是一个模型,那么它的名称空间也将被写入。

代码示例

代码示例来源:origin: com.github.tkurz/sparql-mm

public void toRDF(File file, RDFFormat format) throws RDFHandlerException, IOException {
  Writer writer = Files.newWriter(file, Charset.forName("UTF-8"));
  Rio.write(model, writer, format);
  writer.flush();
  writer.close();
}

代码示例来源:origin: io.redlink/redlink-sdk-java

@Override
public boolean importDataset(Model data, String dataset, boolean cleanBefore) throws RDFHandlerException {
  RDFFormat format = RDFFormat.TURTLE;
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Rio.write(data, out, format);
  return importDataset(new ByteArrayInputStream(out.toByteArray()), format, dataset, cleanBefore);
}

代码示例来源:origin: apache/stanbol

/**
 * @param data
 * @param out
 * @param mediaType
 */
private void writeRdf(Model data, OutputStream out, MediaType mediaType) {
  RDFFormat rdfFormat = Rio.getWriterFormatForMIMEType(mediaType.toString());
  if(rdfFormat == null){
    throw new IllegalStateException("JAX-RS called for unsupported mediaType '"
      + mediaType +"'! If this is a valid RDF type this indicates a missing "
      + "Sesame Serializer implementation. Otherwise please report this "
      + "as a bug for the Stanbol Issue Tracker.");
  }
  try {
    Rio.write(data, out, rdfFormat);
  } catch (RDFHandlerException e) {
    throw new WebApplicationException("Unable to serialize QueryResultList with requested Format '" +
        rdfFormat +"'!", e);
  }
}

代码示例来源:origin: com.powsybl/powsybl-triple-store-impl-blazegraph

private static void write(Model statements, OutputStream out) {
  try (PrintStream pout = new PrintStream(out)) {
    RDFWriter w = new RDFXMLPrettyWriter(pout);
    Rio.write(statements, w);
  } catch (Exception x) {
    throw new TripleStoreException("Writing model statements", x);
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given statement to the given {@link OutputStream} in the given
 * format.
 * <p>
 * 
 * @param st
 *        The statement to be written.
 * @param output
 *        The {@link OutputStream} to write the statement to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statement.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statement.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.8.0
 */
public static void write(Statement st, OutputStream output, RDFFormat dataFormat)
  throws RDFHandlerException
{
  write(st, output, dataFormat, new WriterConfig());
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given single statement to the given {@link Writer} in the given
 * format.
 * <p>
 * 
 * @param statement
 *        A statement to be written.
 * @param output
 *        The {@link Writer} to write the statement to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statement.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statement.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.8.0
 */
public static void write(Statement statement, Writer output, RDFFormat dataFormat)
  throws RDFHandlerException
{
  write(statement, output, dataFormat, new WriterConfig());
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given statements to the given {@link Writer} in the given
 * format.
 * <p>
 * If the collection is a {@link Model}, its namespaces will also be written.
 * 
 * @param model
 *        A collection of statements, such as a {@link Model}, to be written.
 * @param output
 *        The {@link Writer} to write the statements to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statements.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statements.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.7.1
 */
public static void write(Iterable<Statement> model, Writer output, RDFFormat dataFormat)
  throws RDFHandlerException
{
  write(model, output, dataFormat, new WriterConfig());
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given statements to the given {@link OutputStream} in the given
 * format.
 * <p>
 * If the collection is a {@link Model}, its namespaces will also be written.
 * 
 * @param model
 *        A collection of statements, such as a {@link Model}, to be written.
 * @param output
 *        The {@link OutputStream} to write the statements to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statements.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statements.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.7.1
 */
public static void write(Iterable<Statement> model, OutputStream output, RDFFormat dataFormat)
  throws RDFHandlerException
{
  write(model, output, dataFormat, new WriterConfig());
}

代码示例来源:origin: io.redlink/redlink-sdk-java

@Override
public boolean importResource(String resource, Model data, String dataset, boolean cleanBefore) {
  RDFFormat format = RDFFormat.TURTLE;
  log.debug("Importing {} data for resource {} in {}", format.getName(), resource, dataset);
  try {
    java.net.URI target = credentials.buildUrl(getResourceUriBuilder(dataset, resource));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Rio.write(data, out, format);
    InputStream in = new ByteArrayInputStream(out.toByteArray());
    CloseableHttpResponse response;
    if (cleanBefore) {
      response = client.put(target, in, format);
    } else {
      response = client.post(target, in, format);
    }
    try {
      log.debug("Request resolved with {} status code: {}", response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
      return (response.getStatusLine().getStatusCode() == 200);
    } finally {
      response.close();
    }
  } catch (IllegalArgumentException | URISyntaxException | RDFHandlerException | IOException e) {
    log.error("Error importing resource: {}", e.getMessage(), e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given single statement to the given {@link OutputStream} in the
 * given format.
 * 
 * @param st
 *        The statement to be written.
 * @param output
 *        The {@link OutputStream} to write the statement to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statement.
 * @param settings
 *        The {@link WriterConfig} containing setting for configuring the
 *        writer.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statement.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.8.0
 */
public static void write(Statement st, OutputStream output, RDFFormat dataFormat, WriterConfig settings)
  throws RDFHandlerException
{
  final RDFWriter writer = Rio.createWriter(dataFormat, output);
  writer.setWriterConfig(settings);
  write(st, writer);
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given single statement to the given {@link Writer} in the given
 * format.
 * <p>
 * 
 * @param statement
 *        A statement to be written.
 * @param output
 *        The {@link Writer} to write the statement to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statement.
 * @param settings
 *        The {@link WriterConfig} containing settings for configuring the
 *        writer.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statement.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.8.0
 */
public static void write(Statement statement, Writer output, RDFFormat dataFormat, WriterConfig settings)
  throws RDFHandlerException
{
  final RDFWriter writer = Rio.createWriter(dataFormat, output);
  writer.setWriterConfig(settings);
  write(statement, writer);
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given statements to the given {@link OutputStream} in the given
 * format.
 * <p>
 * If the collection is a {@link Model}, its namespaces will also be written.
 * 
 * @param model
 *        A collection of statements, such as a {@link Model}, to be written.
 * @param output
 *        The {@link OutputStream} to write the statements to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statements.
 * @param settings
 *        The {@link WriterConfig} containing settings for configuring the
 *        writer.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statements.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.7.3
 */
public static void write(Iterable<Statement> model, OutputStream output, RDFFormat dataFormat,
    WriterConfig settings)
  throws RDFHandlerException
{
  final RDFWriter writer = Rio.createWriter(dataFormat, output);
  writer.setWriterConfig(settings);
  write(model, writer);
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-obdalib-r2rml

/**
 * the method to write the R2RML mappings
 * from an rdf Model to a file
 * @param os the output target
 */
public void write(OutputStream os) throws Exception {
  try {
    R2RMLMappingManager mm = new SesameR2RMLMappingManagerFactory().getR2RMLMappingManager();
    Collection<TriplesMap> coll = getTripleMaps();
    Model out = mm.exportMappings(coll, Model.class);
    Rio.write(out, os, RDFFormat.TURTLE);
    os.close();
  } catch (Exception e) {
    e.printStackTrace();
    throw e;
  }
}

代码示例来源:origin: org.openrdf.sesame/sesame-rio-api

/**
 * Writes the given statements to the given {@link Writer} in the given
 * format.
 * <p>
 * If the collection is a {@link Model}, its namespaces will also be written.
 * 
 * @param model
 *        A collection of statements, such as a {@link Model}, to be written.
 * @param output
 *        The {@link Writer} to write the statements to.
 * @param dataFormat
 *        The {@link RDFFormat} to use when writing the statements.
 * @param settings
 *        The {@link WriterConfig} containing settings for configuring the
 *        writer.
 * @throws RDFHandlerException
 *         Thrown if there is an error writing the statements.
 * @throws UnsupportedRDFormatException
 *         If no {@link RDFWriter} is available for the specified RDF format.
 * @since 2.7.3
 */
public static void write(Iterable<Statement> model, Writer output, RDFFormat dataFormat,
    WriterConfig settings)
  throws RDFHandlerException
{
  final RDFWriter writer = Rio.createWriter(dataFormat, output);
  writer.setWriterConfig(settings);
  write(model, writer);
}

代码示例来源:origin: com.github.ansell.oas/oas-webservice-impl

Rio.write(myModel, writer, outputFormat);

代码示例来源:origin: projectdanube/xdi2

Rio.write(model, bufferedWriter, RDFFormat.TRIG, writerConfig);
} catch (RDFHandlerException ex) {

代码示例来源:origin: org.openrdf.sesame/sesame-rio-testsuite

private void testSES2030BNodeCollisionsInternal(boolean preserveBNodeIDs)
  throws Exception
{
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  RDFWriter rdfWriter = rdfWriterFactory.getWriter(output);
  setupWriterConfig(rdfWriter.getWriterConfig());
  rdfWriter.startRDF();
  int count = 18;
  for (int i = 0; i < count; i++) {
    BNode bNode2 = vf.createBNode("a" + Integer.toHexString(i).toUpperCase());
    // System.out.println(bNode2.getID());
    rdfWriter.handleStatement(vf.createStatement(uri1, uri2, bNode2));
  }
  rdfWriter.endRDF();
  RDFParser rdfParser = rdfParserFactory.getParser();
  setupParserConfig(rdfParser.getParserConfig());
  if (preserveBNodeIDs) {
    rdfParser.getParserConfig().set(BasicParserSettings.PRESERVE_BNODE_IDS, true);
  }
  Model parsedModel = new LinkedHashModel();
  rdfParser.setRDFHandler(new StatementCollector(parsedModel));
  rdfParser.parse(new ByteArrayInputStream(output.toByteArray()), "");
  // if(potentialObjects.size() != parsedModel.size()) {
  if (count != parsedModel.size()) {
    Rio.write(parsedModel, System.out, RDFFormat.NQUADS);
  }
  assertEquals(count, parsedModel.size());
  // assertEquals(potentialObjects.size(), parsedModel.size());
}

代码示例来源:origin: org.apache.marmotta/marmotta-client-java

Rio.write(results, out, RDFFormat.RDFJSON);
} catch(RDFHandlerException e) {
  throw new IOException(e);

代码示例来源:origin: projectdanube/xdi2

Rio.write(model, bufferedWriter, RDFFormat.JSONLD, writerConfig);
} catch (RDFHandlerException ex) {

代码示例来源:origin: apache/marmotta

Rio.write(results, out, RDFFormat.RDFJSON);
} catch(RDFHandlerException e) {
  throw new IOException(e);

相关文章