Package org.openrdf.rio

Examples of org.openrdf.rio.RDFWriter


    con1.add(ciaScheme, ciaScheme.toExternalForm(), RDFFormat.forFileName(ciaScheme.toExternalForm()));
    con1.add(ciaFacts, ciaFacts.toExternalForm(), RDFFormat.forFileName(ciaFacts.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();
View Full Code Here


    con1.add(ciaScheme, ciaScheme.toExternalForm(), RDFFormat.forFileName(ciaScheme.toExternalForm()));
    con1.add(ciaFacts, ciaFacts.toExternalForm(), RDFFormat.forFileName(ciaFacts.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.setBaseURI(ciaFacts.toExternalForm());
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();
View Full Code Here

      public void writeRequest(OutputStream out)
        throws IOException
      {
        OutputStreamWriter writer = new OutputStreamWriter(out, charset);
        RDFWriter rdf = factory.getWriter(writer);
        try {
          rdf.startRDF();
          for (Map.Entry<String, String> ns : model.getNamespaces().entrySet()) {
            rdf.handleNamespace(ns.getKey(), ns.getValue());
          }
          for (Statement st : model) {
            rdf.handleStatement(st);
          }
          rdf.endRDF();
        }
        catch (RDFHandlerException e) {
          if (e.getCause() instanceof IOException) {
            throw (IOException)e.getCause();
          }
View Full Code Here

   *         If an unsupported query result file format was specified.
   */
  public static void write(GraphResult gqr, RDFFormat format, OutputStream out)
    throws IOException, RDFHandlerException, UnsupportedRDFormatException, StoreException
  {
    RDFWriter writer = Rio.createWriter(format, out);
    try {
      QueryResultUtil.report(gqr, writer);
    }
    catch (RDFHandlerException e) {
      if (e.getCause() instanceof IOException) {
View Full Code Here

    try {
      OutputStream out = new FileOutputStream(file);

      try {
        RDFFormat format = Rio.getWriterFormatForFileName(file.getName());
        RDFWriter writer = Rio.createWriter(format, out);

        writer.startRDF();
        for (Map.Entry<String, String> ns : config.getNamespaces().entrySet()) {
          writer.handleNamespace(ns.getKey(), ns.getValue());
        }
        for (Statement st : config) {
          writer.handleStatement(st);
        }
        writer.endRDF();
      }
      catch (UnsupportedRDFormatException e) {
        throw new StoreConfigException(e);
      }
      catch (RDFHandlerException e) {
View Full Code Here

    String tmpDir = System.getProperty("java.io.tmpdir");
    File tmpFile = new File(tmpDir, "junit-" + name + ".nt");

    OutputStream export = new FileOutputStream(tmpFile);
    try {
      RDFWriter writer = Rio.createWriter(RDFFormat.NTRIPLES, export);

      writer.startRDF();
      for (Statement st : statements) {
        writer.handleStatement(st);
      }
      writer.endRDF();
    }
    finally {
      export.close();
    }
View Full Code Here

    URL rdf = this.getClass().getResource("/testcases/rdfa-test.rdf");

    con1.add(rdf, rdf.toExternalForm(), RDFFormat.forFileName(rdf.toExternalForm()));

    StringWriter writer = new StringWriter();
    RDFWriter rdfWriter = rdfWriterFactory.getWriter(writer);
    rdfWriter.setBaseURI(rdf.toExternalForm());
    con1.export(rdfWriter);

    long before = con1.size();
    con1.close();
View Full Code Here

  @Override
  public void write(OutputStream out)
    throws IOException
  {
    RDFWriter writer = rdfWriterFactory.getWriter(out);
    try {
      // writer.setBaseURI(req.getRequestURL().toString());
      writer.startRDF();

      Set<String> firstNamespaces = null;
      List<Statement> firstStatements = new ArrayList<Statement>(SMALL);

      // Only try to trim namespace if the RDF format supports namespaces
      // in the first place
      trimNamespaces = trimNamespaces && writer.getRDFFormat().supportsNamespaces();

      if (trimNamespaces) {
        // Gather the first few statements
        for (int i = 0; result.hasNext() && i < SMALL; i++) {
          firstStatements.add(result.next());
        }

        // Only trim namespaces if the set is small enough
        trimNamespaces = firstStatements.size() < SMALL;

        if (trimNamespaces) {
          // Gather the namespaces from the first few statements
          firstNamespaces = new HashSet<String>(SMALL);

          for (Statement st : firstStatements) {
            addNamespace(st.getSubject(), firstNamespaces);
            addNamespace(st.getPredicate(), firstNamespaces);
            addNamespace(st.getObject(), firstNamespaces);
            addNamespace(st.getContext(), firstNamespaces);
          }
        }
      }

      // Report namespace prefixes
      for (Map.Entry<String, String> ns : result.getNamespaces().entrySet()) {
        String prefix = ns.getKey();
        String namespace = ns.getValue();
        if (trimNamespaces == false || firstNamespaces.contains(namespace)) {
          writer.handleNamespace(prefix, namespace);
        }
      }

      // Report staements
      for (Statement st : firstStatements) {
        writer.handleStatement(st);
      }

      while (result.hasNext()) {
        Statement st = result.next();
        writer.handleStatement(st);
      }

      writer.endRDF();
    }
    catch (StoreException e) {
      logger.error("Query evaluation error", e);
      throw new IOException("Query evaluation error: " + e.getMessage());
    }
View Full Code Here

  @Override
  public void write(OutputStream out)
    throws IOException
  {
    try {
      RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
      QueryResultUtil.report(graphResult, rdfWriter);
    }
    catch (StoreException e) {
      logger.error("Query evaluation error", e);
      throw new IOException("Query evaluation error: " + e.getMessage());
View Full Code Here

  @Override
  public void write(OutputStream out)
    throws IOException
  {
    try {
      RDFWriter rdfWriter = rdfWriterFactory.getWriter(out);
      // rdfWriter.setBaseURI(requestURL);

      rdfWriter.startRDF();

      for (Map.Entry<String, String> ns : model.getNamespaces().entrySet()) {
        rdfWriter.handleNamespace(ns.getKey(), ns.getValue());
      }

      for (Statement st : model) {
        rdfWriter.handleStatement(st);
      }

      rdfWriter.endRDF();
    }
    catch (RDFHandlerException e) {
      logger.error("Serialization error", e);
      throw new IOException("Serialization error: " + e.getMessage());
    }
View Full Code Here

TOP

Related Classes of org.openrdf.rio.RDFWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.