Search in sources :

Example 81 with IonDatagram

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

the class PrinterTest method testDatagramWithoutSymbols.

@Test
public void testDatagramWithoutSymbols() throws Exception {
    IonDatagram dg = system().newDatagram();
    dg.add().newInt(1);
    checkRendering(ION_1_0 + " 1", dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 82 with IonDatagram

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

the class PrinterTest method testPrintingDatagram.

@Test
public void testPrintingDatagram() throws Exception {
    IonDatagram dg = loader().load("a b c");
    StringBuilder w = new StringBuilder();
    myPrinter.print(dg, w);
    String text = w.toString();
    assertTrue("missing version marker", text.startsWith(ION_1_0 + ' '));
    assertTrue("missing data", text.endsWith(" a b c"));
    // Just force symtab analysis and make sure output is still okay
    dg.getBytes(new byte[dg.byteSize()]);
    text = w.toString();
    assertTrue("missing version marker", text.startsWith(ION_1_0 + ' '));
    assertTrue("missing data", text.endsWith(" a b c"));
    // We shouldn't inject a local table if its not needed.
    String data = "2 '+' [2,'+']";
    String dataWithIvm = ION_1_0 + ' ' + data;
    dg = loader().load(dataWithIvm);
    checkRendering(dataWithIvm, dg);
    myPrinter.setSkipSystemValues(true);
    checkRendering(data, dg);
    myPrinter.setPrintDatagramAsList(true);
    checkRendering("[2,'+',[2,'+']]", dg);
    myPrinter.setPrintDatagramAsList(false);
    myPrinter.setSkipSystemValues(false);
    myPrinter.setJsonMode();
    checkRendering("[2,\"+\",[2,\"+\"]]", dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 83 with IonDatagram

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

the class PrinterTest method testSimplifyingChainedLocalSymtab.

@Test
public void testSimplifyingChainedLocalSymtab() throws Exception {
    myPrinter.myOptions.simplifySystemValues = true;
    String ionText = ION_SYMBOL_TABLE + "::{}" + " x" + " " + ION_SYMBOL_TABLE + "::{}" + " y";
    IonDatagram dg = loader().load(ionText);
    checkRendering(ION_1_0 + " x y", dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test) IntTest(com.amazon.ion.IntTest) BlobTest(com.amazon.ion.BlobTest) ClobTest(com.amazon.ion.ClobTest)

Example 84 with IonDatagram

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

the class IonWriterSystemTree method stepOut.

public void stepOut() throws IOException {
    _Private_IonValue prior = (_Private_IonValue) _current_parent;
    popParent();
    if (_current_parent instanceof IonDatagram && valueIsLocalSymbolTable(prior)) {
        // We just finish writing a symbol table!
        SymbolTable symbol_table = _lst_factory.newLocalSymtab(_catalog, (IonStruct) prior);
        setSymbolTable(symbol_table);
    }
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) com.amazon.ion.impl._Private_Utils.valueIsLocalSymbolTable(com.amazon.ion.impl._Private_Utils.valueIsLocalSymbolTable)

Example 85 with IonDatagram

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

the class IonSystemLite method newDatagram.

public IonDatagram newDatagram() {
    IonCatalog catalog = this.getCatalog();
    IonDatagram dg = newDatagram(catalog);
    return dg;
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonCatalog(com.amazon.ion.IonCatalog)

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