Search in sources :

Example 26 with IonSystem

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

the class _Private_IonBinaryWriterBuilder method fillLegacyDefaults.

/**
 * Fills all properties and returns an immutable builder.
 */
private _Private_IonBinaryWriterBuilder fillLegacyDefaults() {
    // amzn/ion-java/issues/59 Fix this to use the new writer or eliminate it
    // Ensure that we don't modify the user's builder.
    _Private_IonBinaryWriterBuilder b = copy();
    if (b.getSymtabValueFactory() == null) {
        IonSystem system = IonSystemBuilder.standard().build();
        b.setSymtabValueFactory(system);
    }
    SymbolTable initialSymtab = b.getInitialSymbolTable();
    if (initialSymtab == null) {
        initialSymtab = initialSymtab(LocalSymbolTable.DEFAULT_LST_FACTORY, _Private_Utils.systemSymtab(1), b.getImports());
        b.setInitialSymbolTable(initialSymtab);
    } else if (initialSymtab.isSystemTable()) {
        initialSymtab = initialSymtab(LocalSymbolTable.DEFAULT_LST_FACTORY, initialSymtab, b.getImports());
        b.setInitialSymbolTable(initialSymtab);
    }
    return b.immutable();
}
Also used : IonSystem(com.amazon.ion.IonSystem) SymbolTable(com.amazon.ion.SymbolTable)

Example 27 with IonSystem

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

the class _Private_IonBinaryWriterBuilder method fillDefaults.

// =========================================================================
/**
 * Fills all properties and returns an immutable builder.
 */
private _Private_IonBinaryWriterBuilder fillDefaults() {
    // Ensure that we don't modify the user's builder.
    _Private_IonBinaryWriterBuilder b = copy();
    if (b.getSymtabValueFactory() == null) {
        IonSystem system = IonSystemBuilder.standard().build();
        b.setSymtabValueFactory(system);
    }
    return b.immutable();
}
Also used : IonSystem(com.amazon.ion.IonSystem)

Example 28 with IonSystem

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

the class SymbolTableTest method testDupLocalSymbolOnDatagram.

@Test
public void testDupLocalSymbolOnDatagram() throws Exception {
    final IonSystem ion1 = system();
    final SymbolTable st = ion1.newSharedSymbolTable("foobar", 1, Arrays.asList("s1").iterator());
    final IonMutableCatalog cat = new SimpleCatalog();
    cat.putTable(st);
    // amzn/ion-java/issues/46 has the datagram producing something like:
    // $ion_1_0 $ion_symbol_table::{imports:[{name: "foobar", version: 1, max_id: 1}], symbols: ["s1", "l1"]} $11 $12
    // local table should not have "s1", user values should be $10 $11
    IonDatagram dg = ion1.newDatagram(st);
    dg.add().newSymbol("s1");
    dg.add().newSymbol("l1");
    final IonSystem ion2 = newSystem(cat);
    dg = ion2.getLoader().load(dg.getBytes());
    checkSymbol("s1", 10, dg.get(0));
    checkSymbol("l1", 11, dg.get(1));
}
Also used : SimpleCatalog(com.amazon.ion.system.SimpleCatalog) IonSystem(com.amazon.ion.IonSystem) IonDatagram(com.amazon.ion.IonDatagram) SymbolTable(com.amazon.ion.SymbolTable) IonMutableCatalog(com.amazon.ion.IonMutableCatalog) Test(org.junit.Test)

Example 29 with IonSystem

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

the class SymbolTableTest method registerImportedV3.

public SymbolTable registerImportedV3() {
    IonSystem system = system();
    String importingText = SharedSymbolTablePrefix + "{" + "  name:'''imported''', version:3," + "  symbols:[" + "    '''imported 1'''," + // Removed 'imported 2'
    "    null," + "    '''fred3'''," + "    '''fred4'''," + "    '''fred5'''," + "  ]" + "}";
    SymbolTable shared = registerSharedSymtab(importingText);
    assertEquals(IMPORTED_3_MAX_ID, shared.getMaxId());
    SymbolTable importedTable = system.getCatalog().getTable("imported", 3);
    assertSame(shared, importedTable);
    return importedTable;
}
Also used : IonSystem(com.amazon.ion.IonSystem) SymbolTable(com.amazon.ion.SymbolTable)

Example 30 with IonSystem

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

the class MiscStreamingTest method testQuoting.

@Test
@SuppressWarnings("deprecation")
public void testQuoting() throws Exception {
    String s = " \"" + _QuotingString1_ion + "\" '" + _QuotingString2_ion + "' ";
    // buffer should be 22 bytes long
    // cookie (4 bytes)
    // local symbol table (11 bytes):
    // annotation           (1 byte tid, len=10)
    // annot size       (1 byte: len=1)
    // $ion_1_0     (1 byte sid)
    // struct           (1 byte tid, len=7)
    // field 'symbols'  (1 bytes sid)
    // List         (1 byte tid, len=5)
    // str2     (5 bytes)
    // value1 string "str1" (5 bytes: 1 typedesc + 4 text)
    // value2 symbol 'str2' (2 bytes: 1 typedesc + 1 sid)
    IonReader ir = system().newReader(s);
    IonSystem system = system();
    IonBinaryWriter wr = system.newBinaryWriter();
    wr = system.newBinaryWriter();
    wr.writeValues(ir);
    byte[] buffer = wr.getBytes();
    assertSame("this buffer length is known to be 22", buffer.length, 22);
    IonReader sir = system().newReader(s);
    IonReader bir = system().newReader(s);
    checkIteratorForQuotingTest("string", sir);
    checkIteratorForQuotingTest("binary", bir);
}
Also used : IonSystem(com.amazon.ion.IonSystem) IonReader(com.amazon.ion.IonReader) IonBinaryWriter(com.amazon.ion.IonBinaryWriter) IonString(com.amazon.ion.IonString) Test(org.junit.Test) BinaryTest(com.amazon.ion.BinaryTest)

Aggregations

IonSystem (com.amazon.ion.IonSystem)39 Test (org.junit.Test)27 IonValue (com.amazon.ion.IonValue)12 SymbolTable (com.amazon.ion.SymbolTable)10 IonReader (com.amazon.ion.IonReader)8 IonWriter (com.amazon.ion.IonWriter)8 IonDatagram (com.amazon.ion.IonDatagram)6 IonStruct (com.amazon.ion.IonStruct)6 IonCatalog (com.amazon.ion.IonCatalog)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 IonString (com.amazon.ion.IonString)4 com.amazon.ion.impl._Private_IonBinaryWriterBuilder (com.amazon.ion.impl._Private_IonBinaryWriterBuilder)4 com.amazon.ion.impl._Private_IonWriter (com.amazon.ion.impl._Private_IonWriter)4 BinaryTest (com.amazon.ion.BinaryTest)3 IonBinaryWriter (com.amazon.ion.IonBinaryWriter)2 IonType (com.amazon.ion.IonType)2 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)2 IOException (java.io.IOException)2 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2