Search in sources :

Example 31 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class Printer method print.

// =========================================================================
// Print methods
public void print(IonValue value, Appendable out) throws IOException {
    // Copy the options so visitor won't see changes made while printing.
    Options options;
    synchronized (// So we don't clone in the midst of changes
    this) {
        options = myOptions.clone();
    }
    if (true) {
        _print(value, makeVisitor(options, out));
    } else {
        // Bridge to the configurable text writer. This is here for
        // testing purposes. It *almost* works except for printing
        // datagram as list.
        boolean dg = value instanceof IonDatagram;
        _Private_IonTextWriterBuilder o = _Private_IonTextWriterBuilder.standard();
        o.setCharset(IonTextWriterBuilder.ASCII);
        if (dg) {
            if (options.skipSystemValues) {
                o.withMinimalSystemData();
            } else if (options.simplifySystemValues) {
                o.setIvmMinimizing(IvmMinimizing.DISTANT);
                o.setLstMinimizing(LstMinimizing.LOCALS);
            }
        }
        o._blob_as_string = options.blobAsString;
        o._clob_as_string = options.clobAsString;
        o._decimal_as_float = options.decimalAsFloat;
        // TODO datagram as list
        o._sexp_as_list = options.sexpAsList;
        o._skip_annotations = options.skipAnnotations;
        o._string_as_json = options.stringAsJson;
        o._symbol_as_string = options.symbolAsString;
        o._timestamp_as_millis = options.timestampAsMillis;
        o._timestamp_as_string = options.timestampAsString;
        o._untyped_nulls = options.untypedNulls;
        IonWriter writer = o.build(out);
        // TODO doesn't work for datagram since it skips system values
        // value.writeTo(writer);
        _Private_IonSystem system = (_Private_IonSystem) value.getSystem();
        IonReader reader = system.newSystemReader(value);
        writer.writeValues(reader);
        writer.finish();
    }
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) com.amazon.ion.impl._Private_IonSystem(com.amazon.ion.impl._Private_IonSystem) IonWriter(com.amazon.ion.IonWriter) com.amazon.ion.impl._Private_IonTextWriterBuilder(com.amazon.ion.impl._Private_IonTextWriterBuilder)

Example 32 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonReaderTreeSystem method re_init.

// ========================================================================
void re_init(IonValue value, boolean hoisted) {
    _curr = null;
    _eof = false;
    _top = 0;
    if (value instanceof IonDatagram) {
        // IonContainerPrivate containers
        assert (value instanceof _Private_IonContainer);
        IonDatagram dg = (IonDatagram) value;
        _parent = dg;
        _next = null;
        // we want a system reader not: new Children(dg);
        _iter = dg.systemIterator();
    } else {
        _parent = (hoisted ? null : value.getContainer());
        _next = (_Private_IonValue) value;
    }
}
Also used : IonDatagram(com.amazon.ion.IonDatagram)

Example 33 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class SimpleCatalogTest method testBenchmark.

@SuppressWarnings("unchecked")
@Test
public void testBenchmark() {
    Map m = new HashMap();
    String s = "hello";
    m.put("This is a test String.", true);
    m.put(s, true);
    m.put("true", true);
    m.put("false", false);
    m.put("Something", null);
    m.put("12242.124598129", 12242.124598129);
    m.put("long", (long) 9326);
    m.put("12", 12);
    m.put("Almost Done.", true);
    m.put("Date", new Date(-10000));
    HashMap<String, String> hmap = new HashMap();
    for (int i = 0; i < 10; i++) {
        hmap.put("Key " + i, "value " + i);
    }
    TreeMap<String, String> tmap = new TreeMap();
    for (int i = 0; i < 10; i++) {
        tmap.put("Key " + i, "value " + i);
    }
    m.put("hmap", hmap);
    m.put("tmap", tmap);
    IonSystem sys = system();
    IonStruct i_tmap, i_hmap, i_map;
    Set<Entry<String, String>> set;
    i_tmap = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_tmap.add(e.getKey(), is);
    }
    i_hmap = sys.newEmptyStruct();
    set = hmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_hmap.add(e.getKey(), is);
    }
    i_map = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        Object val = e.getValue();
        IonValue ival;
        if (val instanceof String) {
            ival = sys.newString((String) val);
        } else if (e.getKey().equals("tmap")) {
            ival = i_tmap;
        } else if (e.getKey().equals("hmap")) {
            ival = i_hmap;
        } else {
            throw new RuntimeException("ACK! there's something in this map I don't understand!");
        }
        i_map.add(e.getKey(), ival);
    }
    IonDatagram dg = sys.newDatagram(i_map);
    byte[] bytes = dg.getBytes();
    IonValue v2 = sys.singleValue(bytes);
    assertNotNull(v2);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) HashMap(java.util.HashMap) IonString(com.amazon.ion.IonString) TreeMap(java.util.TreeMap) Date(java.util.Date) Entry(java.util.Map.Entry) IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Example 34 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class RoundTripStreamingTest method roundTripBuffer.

roundTripBufferResults roundTripBuffer(String pass, byte[] testBuffer) throws IOException {
    roundTripBufferResults stream = new roundTripBufferResults(pass + " stream");
    roundTripBufferResults tree = new roundTripBufferResults(pass + " tree");
    stream.name = myTestFile.getName() + " (as stream)";
    tree.name = myTestFile.getName() + " (as IonValue)";
    // load() takes ownership of the buffer
    IonDatagram inputDatagram = loader().load(testBuffer.clone());
    stream.utf8_buf = makeText(testBuffer, false);
    stream.utf8_pretty = makeText(testBuffer, true);
    stream.string = makeString(testBuffer);
    stream.binary = makeBinary(testBuffer);
    stream.ion = makeTree(testBuffer);
    checkBinaryHeader(stream.binary);
    // Turn the DOM back into text...
    tree.string = makeString(inputDatagram);
    tree.utf8_buf = utf8(tree.string);
    // FIXME hack
    tree.utf8_pretty = utf8(tree.string);
    tree.binary = makeBinary(inputDatagram);
    tree.ion = inputDatagram;
    checkBinaryHeader(tree.binary);
    tree.compareResultsPass1(stream, myLoader);
    return stream;
}
Also used : IonDatagram(com.amazon.ion.IonDatagram)

Example 35 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class SpanReaderTest method testCallingCurrentSpan.

@Test
public void testCallingCurrentSpan() {
    if (getStreamingMode() == StreamingMode.NEW_STREAMING_INCREMENTAL) {
        // See ion-java/issues/382 and ion-java/issues/383.
        return;
    }
    String text = "null true 3 4e0 5.0 6666-06-06T '7' \"8\" {{\"\"}} {{}} [] () {}";
    IonDatagram dg = loader().load(text);
    Span[] positions = new Span[dg.size()];
    read(text);
    for (int i = 0; i < dg.size(); i++) {
        assertEquals(dg.get(i).getType(), in.next());
        positions[i] = sp.currentSpan();
    }
    expectEof();
    // Collect spans *after* extracting scalar body.
    read(text);
    for (int i = 0; i < dg.size(); i++) {
        IonType t = in.next();
        assertEquals(dg.get(i).getType(), t);
        if (!IonType.isContainer(t)) {
            TestUtils.consumeCurrentValue(in);
        }
    // assertEquals(positions[i], sp.currentSpan());  //FIXME
    }
    expectTopEof();
}
Also used : IonType(com.amazon.ion.IonType) IonDatagram(com.amazon.ion.IonDatagram) Span(com.amazon.ion.Span) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2