Search in sources :

Example 46 with IonStruct

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

the class _Private_CurriedValueFactory method newNullStruct.

// -------------------------------------------------------------------------
public IonStruct newNullStruct() {
    IonStruct v = myFactory.newNullStruct();
    handle(v);
    return v;
}
Also used : IonStruct(com.amazon.ion.IonStruct)

Example 47 with IonStruct

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

the class OptimizedBinaryWriterLengthPatchingTest method testOptimizedWriteLengthPatching.

/**
 * Tests that the internal implementation of binary {@link IonWriter}'s
 * patching mechanism is correct.
 *
 * @see IonWriterSystemBinary
 */
@Test
public void testOptimizedWriteLengthPatching() throws Exception {
    iw = makeWriter();
    // The expected datagram - as values are copied to the IonWriter, we
    // book-keep the values written so as to do an equality check at the end.
    IonDatagram expected = system().newDatagram();
    // === top level ===
    writeAndAddTypeDescLengthVariants(expected);
    // === nested list ===
    iw.stepIn(IonType.LIST);
    IonList expectedNestedList = expected.add().newEmptyList();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedList);
    }
    iw.stepOut();
    // === nested sexp ===
    iw.stepIn(IonType.SEXP);
    IonSexp expectedNestedSexp = expected.add().newEmptySexp();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedSexp);
    }
    iw.stepOut();
    // === nested struct ===
    iw.stepIn(IonType.STRUCT);
    IonStruct expectedNestedStruct = expected.add().newEmptyStruct();
    {
        writeAndAddTypeDescLengthVariants(expectedNestedStruct);
    }
    iw.stepOut();
    // === deeply nested list ===
    iw.stepIn(IonType.LIST);
    IonList nestedList1 = expected.add().newEmptyList();
    {
        writeAndAddTypeDescLengthVariants(nestedList1);
        iw.stepIn(IonType.LIST);
        {
            IonList nestedList2 = nestedList1.add().newEmptyList();
            writeAndAddTypeDescLengthVariants(nestedList2);
        }
        iw.stepOut();
    }
    iw.stepOut();
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonSexp(com.amazon.ion.IonSexp) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) Test(org.junit.Test)

Example 48 with IonStruct

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

the class IonManagedBinaryWriterTest method testNoNewSymbolsAfterFlush.

@Test
public void testNoNewSymbolsAfterFlush() throws Exception {
    writer.writeSymbol("taco");
    writer.flush();
    writer.writeInt(123);
    writer.finish();
    IonDatagram dg = system().getLoader().load(writer.getBytes());
    // Should be IVM SYMTAB taco 123
    assertEquals(4, dg.systemSize());
    assertEquals("$ion_symbol_table", ((IonStruct) dg.systemGet(1)).getTypeAnnotations()[0]);
    assertEquals("taco", ((IonSymbol) dg.systemGet(2)).stringValue());
    assertEquals(123, ((IonInt) dg.systemGet(3)).intValue());
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 49 with IonStruct

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

the class IonManagedBinaryWriterTest method testFlushImmediatelyAfterIVM.

@Test
public void testFlushImmediatelyAfterIVM() throws Exception {
    writer.flush();
    writer.writeSymbol("burrito");
    writer.finish();
    IonReader reader = system().newReader(writer.getBytes());
    reader.next();
    assertEquals(reader.getSymbolTable().findSymbol("taco"), -1);
    assertEquals(reader.getSymbolTable().findSymbol("burrito"), 15);
    assertNull(reader.next());
    IonDatagram dg = system().getLoader().load(writer.getBytes());
    // Should be IVM SYMTAB burrito
    assertEquals(3, dg.systemSize());
    assertEquals("$ion_symbol_table", ((IonStruct) dg.systemGet(1)).getTypeAnnotations()[0]);
    assertEquals("burrito", ((IonSymbol) dg.systemGet(2)).stringValue());
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) Test(org.junit.Test)

Example 50 with IonStruct

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

the class SymbolTableTest method checkFirstImport.

static void checkFirstImport(String name, int version, String[] expectedSymbols, IonStruct symtab) throws IOException {
    IonList imports = (IonList) symtab.get(SystemSymbols.IMPORTS);
    IonStruct i0 = (IonStruct) imports.get(0);
    checkString(name, i0.get(SystemSymbols.NAME));
    checkInt(version, i0.get(SystemSymbols.VERSION));
    checkInt(expectedSymbols.length, i0.get(SystemSymbols.MAX_ID));
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonList(com.amazon.ion.IonList)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3