Search in sources :

Example 1 with CookJsonGenerator

use of org.yuanheng.cookjson.CookJsonGenerator in project jaqy by Teradata.

the class JsonExporter method export.

@Override
public long export(JaqyResultSet rs, JaqyInterpreter interpreter) throws Exception {
    JsonProvider provider = new CookJsonProvider();
    CookJsonGenerator g = null;
    HashMap<String, Object> config = new HashMap<String, Object>();
    switch(m_format) {
        case Text:
            {
                config.put(CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_JSON);
                if (m_pretty)
                    config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
                switch(m_binaryFormat) {
                    case Base64:
                        config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_BASE64);
                        break;
                    case Hex:
                        config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_HEX);
                        break;
                }
                g = (CookJsonGenerator) provider.createGeneratorFactory(config).createGenerator(m_out);
                break;
            }
        case Bson:
            config.put(CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
            g = (CookJsonGenerator) provider.createGeneratorFactory(config).createGenerator(m_os);
            break;
    }
    long count = JsonUtils.print(interpreter.getGlobals(), g, rs, 0);
    g.close();
    return count;
}
Also used : CookJsonProvider(org.yuanheng.cookjson.CookJsonProvider) HashMap(java.util.HashMap) CookJsonProvider(org.yuanheng.cookjson.CookJsonProvider) JsonProvider(javax.json.spi.JsonProvider) CookJsonGenerator(org.yuanheng.cookjson.CookJsonGenerator)

Example 2 with CookJsonGenerator

use of org.yuanheng.cookjson.CookJsonGenerator in project jaqy by Teradata.

the class JsonPrinter method print.

@Override
public long print(JaqyResultSet rs, PrintWriter pw, long limit, JaqyInterpreter interpreter) throws Exception {
    JsonProvider provider = new CookJsonProvider();
    HashMap<String, Object> config = new HashMap<String, Object>();
    config.put(CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_JSON);
    if (m_pretty)
        config.put(JsonGenerator.PRETTY_PRINTING, Boolean.TRUE);
    switch(m_binaryFormat) {
        case Base64:
            config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_BASE64);
            break;
        case Hex:
            config.put(CookJsonProvider.BINARY_FORMAT, CookJsonProvider.BINARY_FORMAT_HEX);
            break;
    }
    CookJsonGenerator g = (CookJsonGenerator) provider.createGeneratorFactory(config).createGenerator(pw);
    long count = JsonUtils.print(interpreter.getGlobals(), g, rs, limit);
    pw.println();
    return count;
}
Also used : CookJsonProvider(org.yuanheng.cookjson.CookJsonProvider) HashMap(java.util.HashMap) CookJsonProvider(org.yuanheng.cookjson.CookJsonProvider) JsonProvider(javax.json.spi.JsonProvider) CookJsonGenerator(org.yuanheng.cookjson.CookJsonGenerator)

Aggregations

HashMap (java.util.HashMap)2 JsonProvider (javax.json.spi.JsonProvider)2 CookJsonGenerator (org.yuanheng.cookjson.CookJsonGenerator)2 CookJsonProvider (org.yuanheng.cookjson.CookJsonProvider)2