Search in sources :

Example 6 with ByteWriter

use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.

the class DefaultRenderer method renderFieldContentPossiblyNotDecoded.

private void renderFieldContentPossiblyNotDecoded(XMLWriter writer, Hit hit, boolean probablyNotDecoded, String fieldName) throws IOException {
    boolean dumpedRaw = false;
    if (probablyNotDecoded && (hit instanceof FastHit)) {
        writer.closeStartTag();
        if ((writer.getWriter() instanceof ByteWriter) && utf8Output) {
            dumpedRaw = UserTemplate.dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, fieldName);
        }
        if (dumpedRaw) {
            // let the xml writer note that this tag had content
            writer.content("", false);
        }
    }
    if (!dumpedRaw) {
        String xmlval = hit.getFieldXML(fieldName);
        if (xmlval == null) {
            xmlval = "(null)";
        }
        writer.escapedContent(xmlval, false);
    }
}
Also used : FastHit(com.yahoo.prelude.fastsearch.FastHit) ByteWriter(com.yahoo.io.ByteWriter) Utf8String(com.yahoo.text.Utf8String)

Example 7 with ByteWriter

use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.

the class TemplateTestCase method testASCIIQuoting.

public void testASCIIQuoting() throws java.io.IOException {
    stream.reset();
    byte[] c = new byte[] { 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
    ByteWriter bw = new ByteWriter(stream, encoder);
    UserTemplate.dumpAndXMLQuoteUTF8(bw, c);
    bw.close();
    String res = stream.toString("UTF-8");
    String correct = "abc\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\t\n\\u000B\\u000C\r\\u000E\\u000F\\u0010\\u0011";
    assertEquals(correct, res);
}
Also used : ByteWriter(com.yahoo.io.ByteWriter)

Example 8 with ByteWriter

use of com.yahoo.io.ByteWriter in project vespa by vespa-engine.

the class TemplateTestCase method testXMLQuoting.

public void testXMLQuoting() throws java.io.IOException {
    stream.reset();
    // c = <s>&gt;
    byte[] c = new byte[] { 60, 115, 62, 38, 103, 116, 59 };
    ByteWriter bw = new ByteWriter(stream, encoder);
    UserTemplate.dumpAndXMLQuoteUTF8(bw, c);
    bw.close();
    String res = stream.toString("UTF-8");
    String correct = "&lt;s&gt;&amp;gt;";
    assertEquals(correct, res);
}
Also used : ByteWriter(com.yahoo.io.ByteWriter)

Aggregations

ByteWriter (com.yahoo.io.ByteWriter)8 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Utf8String (com.yahoo.text.Utf8String)3 Charset (java.nio.charset.Charset)2 CharsetEncoder (java.nio.charset.CharsetEncoder)2 Document (com.yahoo.document.Document)1 FieldValue (com.yahoo.document.datatypes.FieldValue)1 Raw (com.yahoo.document.datatypes.Raw)1