public static String asString(Graph graph) throws RDFHandlerException { OutputStream stream = new ByteArrayOutputStream(); Rio.write(graph, stream, RDFFormat.JSONLD); return stream.toString(); }
public static String asString(Graph graph) throws RDFHandlerException { OutputStream stream = new ByteArrayOutputStream(); RDFWriter writer = Utils.getRioWriter(stream); Rio.write(graph, writer); return stream.toString(); }
public static void main(String[] args) throws Exception { InputStream resourceAsStream = new FileInputStream(args[0]); Model model = Rio.parse(resourceAsStream, "", RDFFormat.NQUADS); Rio.write(model, new FileOutputStream(args[1]), RDFFormat.TURTLE); } }
public static String asString(Graph graph) throws RDFHandlerException { OutputStream stream = new ByteArrayOutputStream(); RDFWriter writer = Utils.getRioWriter(stream); Rio.write(graph, writer); return stream.toString(); }
/** * 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. */ public static void write(Statement statement, Writer output, RDFFormat dataFormat) throws RDFHandlerException { write(statement, output, dataFormat, new WriterConfig()); }
@Override public void commit() throws RdfProcessingFailedException { try { inputStream.close(); FileWriter newFileWriter = new FileWriter(descriptionFile, false); //false for overwrite file (true=concat) Rio.write(model, newFileWriter, RDFFormat.RDFXML); newFileWriter.flush(); newFileWriter.close(); importStatus.setStatus("Description saved"); } catch (IOException e) { throw new RdfProcessingFailedException(e); } }
/** * 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. */ public static void write(Statement st, OutputStream output, RDFFormat dataFormat) throws RDFHandlerException { write(st, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Iterable<Statement> model, OutputStream output, RDFFormat dataFormat) throws RDFHandlerException { write(model, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Iterable<Statement> model, OutputStream output, RDFFormat dataFormat) throws RDFHandlerException { write(model, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Iterable<Statement> model, Writer output, RDFFormat dataFormat) throws RDFHandlerException { write(model, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Statement st, OutputStream output, RDFFormat dataFormat) throws RDFHandlerException { write(st, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Statement statement, Writer output, RDFFormat dataFormat) throws RDFHandlerException { write(statement, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Statement statement, Writer output, RDFFormat dataFormat) throws RDFHandlerException { write(statement, output, dataFormat, new WriterConfig()); }
/** * 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. */ public static void write(Statement st, OutputStream output, RDFFormat dataFormat) throws RDFHandlerException { write(st, output, dataFormat, new WriterConfig()); }
private void createDescriptionNode(Description description, RDFFormat parseFormat, Interpreter interpreter) { try { Model model = Rio.parse(IOUtils.toInputStream(description.getRawContent()), "", parseFormat); ByteArrayOutputStream out = new ByteArrayOutputStream(); Rio.write(model, out, RDFFormat.JSONLD); ObjectMapper mapper = new ObjectMapper(); content = mapper.readTree(out.toString()); } catch (Exception e) { // catch all e.g. org.xml.sax.SAXParseException rawContent = description.getRawContent(); error = new ErrorView(e, interpreter); } } }
@Override protected void writeInternal(Model model, HttpOutputMessage httpOutputMessage) { runAsSystem( () -> { try { Rio.write(model, httpOutputMessage.getBody(), TURTLE); httpOutputMessage.getBody().close(); } catch (IOException e) { throw new UncheckedIOException(e); } }); } }
private static void write(Model m, OutputStream out) { try (PrintStream pout = new PrintStream(out)) { RDFWriter w = new PowsyblWriter(pout); w.getWriterConfig().set(BasicWriterSettings.PRETTY_PRINT, true); Rio.write(m, w); } }
private void removeModel(Model m) throws RepositoryException { RDFFormat format = RDFFormat.BINARY; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); Rio.write(m, out, format); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); client.removeData(in, null, format); } catch (RDFHandlerException e) { throw new RepositoryException("error while writing statement", e); } catch (RDFParseException e) { throw new RepositoryException(e); } catch (IOException e) { throw new RepositoryException(e); } }
private void removeModel(Model m) throws RepositoryException { RDFFormat format = RDFFormat.BINARY; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); Rio.write(m, out, format); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); client.removeData(in, null, format); } catch (RDFHandlerException e) { throw new RepositoryException("error while writing statement", e); } catch (RDFParseException e) { throw new RepositoryException(e); } catch (IOException e) { throw new RepositoryException(e); } }
private void removeModel(Model m) throws RepositoryException { RDFFormat format = RDFFormat.BINARY; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); Rio.write(m, out, format); ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); client.removeData(in, null, format); } catch (RDFHandlerException e) { throw new RepositoryException("error while writing statement", e); } catch (RDFParseException e) { throw new RepositoryException(e); } catch (IOException e) { throw new RepositoryException(e); } }