use of org.apache.jena.hadoop.rdf.types.NodeTupleWritable in project jena by apache.
the class RdfTypesTest method tuple_writable_01.
/**
* Basic tuple writable round tripping test
*
* @throws IOException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws ClassNotFoundException
*/
@Test
public void tuple_writable_01() throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
Tuple<Node> t = tuple(NodeFactory.createURI("http://one"), NodeFactory.createURI("http://two"), NodeFactory.createLiteral("value"), NodeFactory.createLiteral("foo"), NodeFactory.createURI("http://three"));
NodeTupleWritable tw = new NodeTupleWritable(t);
testWriteRead(tw, tw);
}
use of org.apache.jena.hadoop.rdf.types.NodeTupleWritable in project jena by apache.
the class AbstractNodeWriter method writeValue.
/**
* Writes the given value
* <p>
* If the value is one of the RDF primitives - {@link NodeWritable},
* {@link TripleWritable}, {@link QuadWritable} and
* {@link NodeTupleWritable} - then it is formatted as a series of nodes
* separated by the separator. Otherwise it is formatted by simply calling
* {@code toString()} on it.
* </p>
*
* @param value
* Values
*/
protected void writeValue(TValue value) {
// Handle null specially
if (value instanceof NullWritable || value == null)
return;
// Handle RDF primitives specially and format them as proper nodes
if (value instanceof NodeWritable) {
this.writeKey((NodeWritable) value);
} else if (value instanceof TripleWritable) {
Triple t = ((TripleWritable) value).get();
this.writeNodes(t.getSubject(), t.getPredicate(), t.getObject());
} else if (value instanceof QuadWritable) {
Quad q = ((QuadWritable) value).get();
this.writeNodes(q.getGraph(), q.getSubject(), q.getPredicate(), q.getObject());
} else if (value instanceof NodeTupleWritable) {
Tuple<Node> tuple = ((NodeTupleWritable) value).get();
Node[] n = new Node[tuple.len()];
tuple.copyInto(n);
this.writeNodes(n);
} else {
// For arbitrary values just toString() them
this.writer.write(value.toString());
}
}
Aggregations