Search in sources :

Example 51 with SymbolTable

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

the class LocalSymbolTableTest method testInternUnknownText.

@Test
public void testInternUnknownText() {
    SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC, ST_FRED_V2, ST_GINGER_V1);
    String D = "d";
    checkUnknownSymbol(D, st);
    SymbolToken tok = st.intern(D);
    assertSame(D, tok.getText());
    assertEquals(st.getImportedMaxId() + 4, tok.getSid());
    // Force a new instance
    tok = st.intern(new String(D));
    assertSame(D, tok.getText());
    assertEquals(st.getImportedMaxId() + 4, tok.getSid());
}
Also used : SymbolToken(com.amazon.ion.SymbolToken) SymbolTable(com.amazon.ion.SymbolTable) com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable(com.amazon.ion.impl._Private_Utils.copyLocalSymbolTable) Test(org.junit.Test)

Example 52 with SymbolTable

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

the class LocalSymbolTableTest method testCopyLST.

@Test
public void testCopyLST() {
    SymbolTable orig = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC);
    // method under test
    SymbolTable copy = copyLocalSymbolTable(orig);
    assertNotSame(orig, copy);
    assertTrue(copy.isLocalTable());
    int systemMaxId = orig.getSystemSymbolTable().getMaxId();
    checkSymbol("a", systemMaxId + 1, copy.find("a"));
    checkSymbol("b", systemMaxId + 2, copy.find("b"));
    checkSymbol("c", systemMaxId + 3, copy.find("c"));
}
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 53 with SymbolTable

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSupersetWriterImport.

/**
 * Writer's imports superset of Reader's: (could be) fully optimized.
 * TODO amzn/ion-java/issues/18 at the moment the compatability code requires
 *      exact-match on imports.
 */
@Test
public void testOptimizedWriteValueSupersetWriterImport() throws Exception {
    SymbolTable fred2 = Symtabs.register("fred", 2, catalog());
    byte[] source = encode(importFred1 + "fred_1 123 null");
    ir = makeReaderProxy(source);
    iw = makeWriter(fred2);
    checkWriteValueWithIncompatibleSymtab();
    checkWriteValueWithIncompatibleSymtab();
    checkWriteValueWithIncompatibleSymtab();
    iw.close();
    assertIonIteratorEquals(system().iterate(source), system().iterate(outputByteArray()));
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 54 with SymbolTable

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

the class IonSystemLite method newDatagram.

public IonDatagram newDatagram(IonCatalog catalog, SymbolTable... imports) {
    SymbolTable defaultSystemSymtab = getSystemSymbolTable();
    SymbolTable symbols = initialSymtab(_lstFactory, defaultSystemSymtab, imports);
    IonDatagramLite dg = newDatagram(catalog);
    dg.appendTrailingSymbolTable(symbols);
    return dg;
}
Also used : SymbolTable(com.amazon.ion.SymbolTable)

Example 55 with SymbolTable

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

the class _Private_IonTextWriterBuilder method build.

/**
 * Assumes that {@link #fillDefaults()} has been called.
 */
private IonWriter build(_Private_FastAppendable appender) {
    IonCatalog catalog = getCatalog();
    SymbolTable[] imports = getImports();
    // TODO We shouldn't need a system here
    IonSystem system = IonSystemBuilder.standard().withCatalog(catalog).build();
    SymbolTable defaultSystemSymtab = system.getSystemSymbolTable();
    IonWriterSystemText systemWriter = (getCallbackBuilder() == null ? new IonWriterSystemText(defaultSystemSymtab, this, appender) : new IonWriterSystemTextMarkup(defaultSystemSymtab, this, appender));
    SymbolTable initialSymtab = initialSymtab(((_Private_ValueFactory) system).getLstFactory(), defaultSystemSymtab, imports);
    return new IonWriterUser(catalog, system, systemWriter, initialSymtab);
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonCatalog(com.amazon.ion.IonCatalog) SymbolTable(com.amazon.ion.SymbolTable)

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