FmtUtils { public static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt) { StringBuilder buffer = new StringBuilder() ; boolean first = true ; for (Triple triple : pattern ) { if ( ! first ) buffer.append("\n") ; stringForTriple(buffer, triple, sCxt) ; buffer.append(" ." ) ; out.print(buffer.toString()) ; buffer.setLength(0) ; first = false ; } }  static SerializationContext sCxt(); static SerializationContext sCxt(PrefixMapping pmap); static String stringForTriple( Triple triple ); static String stringForTriple(Triple triple, PrefixMapping prefixMap); static String stringForTriple(Triple triple, SerializationContext sCxt); static void stringForTriple(StringBuilder result, Triple triple, SerializationContext sCxt); static String stringForQuad(Quad quad, PrefixMapping prefixMap); static String stringForQuad(Quad quad); static String stringForQuad(Quad quad, SerializationContext sCxt); static void stringForQuad(StringBuilder sb, Quad quad, SerializationContext sCxt); static void formatPattern(IndentedWriter out, BasicPattern pattern, SerializationContext sCxt); static String stringForObject(Object obj); static String stringForRDFNode(RDFNode obj); static String stringForRDFNode(RDFNode obj, SerializationContext context); static String stringForLiteral(Node_Literal literal, SerializationContext context); static void stringForLiteral(StringBuilder result, Node_Literal literal, SerializationContext context); static String stringForString(String str); static String stringForResource(Resource r); static String stringForResource(Resource r, SerializationContext context); static String stringForNode(Node n); static void stringForNode(StringBuilder result, Node n); static String stringForNode(Node n, PrefixMapping prefixMap); static void stringForNode(StringBuilder result, Node n, PrefixMapping prefixMap); static String stringForNode(Node n, Prologue prologue); static String stringForNode(Node n, SerializationContext context); static void stringForNode(StringBuilder result, Node n, SerializationContext context); static String stringForURI(String uri); static void stringForURI(StringBuilder target, String uri); static String stringForURI(String uri, Prologue prologue); static String stringForURI(String uri, String baseIRI); static String stringForURI(String uri, SerializationContext context); static void stringForURI(StringBuilder result, String uri, SerializationContext context); static String stringForURI(String uri, PrefixMapping mapping); static String stringForURI(String uri, String base, PrefixMapping mapping); static void stringForURI(StringBuilder result, String uri, String base, PrefixMapping mapping); static String abbrevByBase(String uri, String base); static String stringEsc(String s); static String stringEsc(String s, boolean singleLineString); static void stringEsc(StringBuilder sbuff, String s); static void stringEsc(StringBuilder sbuff, String s, boolean singleLineString); static void resetBNodeLabels(); static boolean multiLineExpr; static boolean printOpName; }
@Test public void formatPattern_2_triples() { BasicPattern basicPattern = new BasicPattern() ; basicPattern.add(getTriple()) ; basicPattern.add(getTriple2()) ; ByteArrayOutputStream os = new ByteArrayOutputStream() ; try(IndentedWriter iw = new IndentedWriter(os)) { SerializationContext sc = new SerializationContext() ; FmtUtils.formatPattern(iw, basicPattern, sc) ; } assertEquals("<n1> <n2> \"l3\" .\n" + "<nb1> <nb2> \"lb3\" .", new String(os.toByteArray())) ; }
@Test public void testFormatBGP_1() { IndentedLineBuffer b = new IndentedLineBuffer() ; BasicPattern bgp = SSE.parseBGP("(prefix ((zz: <"+aUri+">)) (bgp (zz:s zz:p zz:o)))") ; FmtUtils.formatPattern(b, bgp, getContext()) ; assertEquals("zz:s zz:p zz:o .", b.toString()) ; }
@Test public void testFormatBGP_2() { IndentedLineBuffer b = new IndentedLineBuffer() ; BasicPattern bgp = SSE.parseBGP("(prefix ((zz: <"+aUri+">)) (bgp (zz:s zz:p zz:o) (zz:s zz:p 123) ))") ; FmtUtils.formatPattern(b, bgp, getContext()) ; assertEquals("zz:s zz:p zz:o .\nzz:s zz:p 123 .", b.toString()) ; }