package com.github.commonsrdf.dummyimpl;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

import org.junit.Before;
import org.junit.Test;

import com.github.commonsrdf.api.BlankNode;
import com.github.commonsrdf.api.IRI;

public class TestWritingGraph {

	private GraphImpl graph;

	@Before
	public void createGraph() throws Exception {
		graph = new GraphImpl();
		BlankNode subject = new BlankNodeImpl("subj");
		IRI predicate = new IRIImpl("pred");
		// 200k triples should do
		for (int i=0; i<200000; i++) {
			graph.add(subject, predicate, 
					new LiteralImpl("Example " + i, "en"));		
		}		
	}
	
	@Test
	public void writeGraphFromStream() throws Exception {
		Path graphFile = Files.createTempFile("graph", ".nt");
		System.out.println("From stream: " + graphFile);		
		Stream<CharSequence> stream = graph.getTriples().unordered().parallel().
				map(t -> t.toString());
		Files.write(graphFile, 
				stream::iterator,
				Charset.forName("UTF-8"));
	}

	@Test
	public void writeGraphFromStreamFiltered() throws Exception {
		Path graphFile = Files.createTempFile("graph", ".nt");		
		System.out.println("Filtered stream: " + graphFile);
		BlankNode subject = new BlankNodeImpl("subj"); 
		IRI predicate = new IRIImpl("pred");
		Stream<CharSequence> stream = graph.getTriples(subject, predicate, null).
				map(t -> t.toString());
		Files.write(graphFile, 
				stream::iterator,
				Charset.forName("UTF-8"));
		
	}

}
 
@@ -922,39 +922,40 @@
 ().%0A%09%09%09%09map(
-t -%3E t.
+Object::
 toString
 ());%0A%09%09Files
@@ -934,34 +934,32 @@
 Object::toString
-()
 );%0A%09%09Files.write
@@ -1389,23 +1389,24 @@
 map(
-t -%3E t.
+Object::
 toString
 ());
@@ -1401,18 +1401,16 @@
 toString
-()
 );%0A%09%09Fil

Use Object::toString