/** * {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { Node metaGraphNode = NodeSerializer.readURI(in); int nbQuads = in.readInt(); String subjectPredicateString = NodeSerializer.readString(in); String[] subjectPredicateValues = subjectPredicateString.split(" "); Builder<Quadruple> quadruples = new ImmutableList.Builder<Quadruple>(); for (int i = 0; i < nbQuads; i++) { Node object = NodeSerializer.readLiteralOrURI(in); quadruples.add(new Quadruple( metaGraphNode, NodeFactory.createURI(subjectPredicateValues[i]), NodeFactory.createURI(subjectPredicateValues[i + nbQuads]), object, false, true)); } this.quadruples = quadruples.build(); }
NodeSerializer.writeURI(out, this.quadruples.get(0) .createMetaGraphNode()); NodeSerializer.writeString(out, buffer.toString()); NodeSerializer.writeLiteralOrURI(out, this.quadruples.get(i) .getObject());
public static Node readLiteralOrURI(ObjectInput in) throws IOException { byte bitmap = in.readByte(); boolean isLiteral = (1 & (bitmap >> 2)) == 1; boolean hasLanguageTag = (1 & (bitmap >> 1)) == 1; boolean hasDatatype = (1 & bitmap) == 1; if (isLiteral) { String literalValue = in.readUTF(); String languageTag = null; String datatypeURI = null; if (hasLanguageTag) { languageTag = readString(in); } if (hasDatatype) { datatypeURI = readString(in); } return NodeFactory.createLiteral( literalValue, languageTag, hasDatatype ? TypeMapper.getInstance().getSafeTypeByName( datatypeURI) : null); } else { return readURI(in); } }
public static void writeLiteralOrURI(ObjectOutput out, Node node) throws IOException { boolean isLiteral = node.isLiteral(); boolean hasLanguageTag = false; boolean hasDatatype = false; if (isLiteral) { hasLanguageTag = !node.getLiteralLanguage().isEmpty(); hasDatatype = node.getLiteralDatatypeURI() != null; } byte bitmap = createLiteralBitmap(isLiteral, hasLanguageTag, hasDatatype); // writes a bitmap to indicate whether the object value is a literal // and if it embeds a language tag and/or a datatype out.writeByte(bitmap); if (isLiteral) { // a literal may contain unicode characters out.writeUTF(node.getLiteralLexicalForm()); if (hasLanguageTag) { writeString(out, node.getLiteralLanguage()); } if (hasDatatype) { writeString(out, node.getLiteralDatatypeURI()); } } else { writeString(out, node.toString()); } }
public static Node readURI(ObjectInput in) throws IOException { return NodeFactory.createURI(readString(in)); }
public static void writeURI(ObjectOutput out, Node node) throws IOException { writeString(out, node.getURI()); }
/** * {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { String[] chunks = new String(in.readUTF()).split(" "); this.nodes[0] = this.extractAndSetMetaInformation(NodeFactory.createURI(chunks[0])); this.nodes[1] = NodeFactory.createURI(chunks[1]); this.nodes[2] = NodeFactory.createURI(chunks[2]); this.nodes[3] = NodeSerializer.readLiteralOrURI(in); }
/** * {@inheritDoc} */ @Override public void writeExternal(ObjectOutput out) throws IOException { // graph, subject and predicate are necessarily IRI values String graph = this.createMetaGraphNode().getURI(); String subject = this.nodes[1].toString(); String predicate = this.nodes[2].toString(); StringBuilder gsp = new StringBuilder(graph); gsp.append(' '); gsp.append(subject); gsp.append(' '); gsp.append(predicate); out.writeUTF(gsp.toString()); NodeSerializer.writeLiteralOrURI(out, this.nodes[3]); }
/** * {@inheritDoc} */ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { byte bitmap = in.readByte(); boolean isGraphSet = (1 & (bitmap >> 0)) == 1; boolean isSubjectSet = (1 & (bitmap >> 1)) == 1; boolean isPredicateSet = (1 & (bitmap >> 2)) == 1; boolean isObjectSet = (1 & (bitmap >> 3)) == 1; if (isGraphSet || isSubjectSet || isPredicateSet) { String[] chunks = new String(in.readUTF()).split(" "); int i = 0; if (isGraphSet) { super.nodes[0] = NodeFactory.createURI(chunks[i]); i++; } if (isSubjectSet) { super.nodes[1] = NodeFactory.createURI(chunks[i]); i++; } if (isPredicateSet) { super.nodes[2] = NodeFactory.createURI(chunks[i]); } } if (isObjectSet) { super.nodes[3] = NodeSerializer.readLiteralOrURI(in); } }
NodeSerializer.writeLiteralOrURI(out, super.nodes[3]);