Search in sources :

Example 46 with SymbolTable

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

the class IonWriterTestCase method testWritingWithSystemImport.

@Test
public void testWritingWithSystemImport() throws Exception {
    final int FRED_ID_OFFSET = systemMaxId();
    final int LOCAL_ID_OFFSET = FRED_ID_OFFSET + FRED_MAX_IDS[1];
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    iw = makeWriter(system().getSystemSymbolTable(), fred1);
    iw.writeSymbol("fred_2");
    iw.writeSymbol("localSym");
    byte[] bytes = outputByteArray();
    IonDatagram dg = loader().load(bytes);
    assertEquals(4, dg.systemSize());
    IonValue f2sym = dg.systemGet(2);
    IonValue local = dg.systemGet(3);
    checkSymbol("fred_2", FRED_ID_OFFSET + 2, f2sym);
    checkSymbol("localSym", local);
    SymbolTable symtab = f2sym.getSymbolTable();
    assertSame(symtab, local.getSymbolTable());
    SymbolTable[] importedTables = symtab.getImportedTables();
    assertEquals(1, importedTables.length);
    assertSame(fred1, importedTables[0]);
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 47 with SymbolTable

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

the class IonWriterTestCase method testWriteValuesWithSymtab.

@Test
public void testWriteValuesWithSymtab() throws Exception {
    SymbolTable fredSymtab = Symtabs.register(Symtabs.FRED_NAME, 1, catalog());
    SymbolTable gingerSymtab = Symtabs.register(Symtabs.GINGER_NAME, 1, catalog());
    String gingerSym = gingerSymtab.findKnownSymbol(1);
    // First setup some data to be copied.
    IonDatagram dg = system().newDatagram(gingerSymtab);
    dg.add().newSymbol(gingerSym);
    IonReader r = system().newReader(dg.getBytes());
    // Now copy that data into a non-top-level context
    iw = makeWriter(fredSymtab);
    iw.stepIn(IonType.LIST);
    iw.writeValues(r);
    iw.stepOut();
    IonDatagram result = reload();
    IonList l = (IonList) result.get(0);
    assertEquals(1, l.size());
    IonSymbol s = (IonSymbol) l.get(0);
    // Should've assigned a new SID
    checkSymbol(gingerSym, s);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) IonReader(com.amazon.ion.IonReader) SymbolTable(com.amazon.ion.SymbolTable) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 48 with SymbolTable

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

the class LocalSymbolTableTest method testCopyLSTThenAddSymbols.

@Test
public void testCopyLSTThenAddSymbols() {
    SymbolTable orig = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC);
    // method under test
    SymbolTable copy = copyLocalSymbolTable(orig);
    // interning in copy doesn't modify orig
    assertNull(orig.find("amazon"));
    copy.intern("amazon");
    assertNull(orig.find("amazon"));
    // interning in orig doesn't modify copy
    assertNull(copy.find("dotcom"));
    orig.intern("dotcom");
    assertNull(copy.find("dotcom"));
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable(com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable) Test(org.junit.Test)

Example 49 with SymbolTable

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

the class LocalSymbolTableTest method testInternNull.

@Test(expected = NullPointerException.class)
public void testInternNull() {
    SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC);
    st.intern(null);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable(com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable) Test(org.junit.Test)

Example 50 with SymbolTable

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

the class LocalSymbolTableTest method testInternKnownText.

@Test
public void testInternKnownText() {
    SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC, ST_FRED_V2, ST_GINGER_V1);
    internKnownText(st);
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable(com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable) Test(org.junit.Test)

Aggregations

SymbolTable (com.amazon.ion.SymbolTable)177 Test (org.junit.Test)105 IonValue (com.amazon.ion.IonValue)21 IonDatagram (com.amazon.ion.IonDatagram)18 com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable (com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable)17 SymbolToken (com.amazon.ion.SymbolToken)14 IonStruct (com.amazon.ion.IonStruct)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 IonWriter (com.amazon.ion.IonWriter)12 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)12 IonReader (com.amazon.ion.IonReader)11 IonSystem (com.amazon.ion.IonSystem)10 IOException (java.io.IOException)9 IonType (com.amazon.ion.IonType)8 ArrayList (java.util.ArrayList)7 IonException (com.amazon.ion.IonException)6 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)6 com.amazon.ion.impl.bin._Private_IonRawWriter (com.amazon.ion.impl.bin._Private_IonRawWriter)6 IonCatalog (com.amazon.ion.IonCatalog)5 IonList (com.amazon.ion.IonList)5