Search in sources :

Example 96 with SymbolTable

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

the class IonReaderLookaheadBufferTest method rewindToValueStartWithLstAppend.

@Test
public void rewindToValueStartWithLstAppend() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IonWriter writer = IonBinaryWriterBuilder.standard().withLocalSymbolTableAppendEnabled().build(out);
    writer.writeSymbol("abc");
    writer.flush();
    writer.writeSymbol("def");
    writer.close();
    InputStream input = new ByteArrayInputStream(out.toByteArray());
    IonReaderLookaheadBuffer lookahead = new IonReaderLookaheadBuffer(builder.build(), input);
    lookahead.fillInput();
    IonReader reader = lookahead.newIonReader(IonReaderBuilder.standard());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("abc", reader.stringValue());
    assertTrue(lookahead.moreDataRequired());
    lookahead.fillInput();
    assertFalse(lookahead.moreDataRequired());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("def", reader.stringValue());
    lookahead.rewindToValueStart();
    // 2-byte value (0x71 0x0B). No IVM or symbol table.
    assertEquals(2, lookahead.available());
    assertEquals(IonType.SYMBOL, reader.next());
    assertEquals("def", reader.stringValue());
    // Note: if mark() / rewind() is used instead of rewindToValueStart(), the following lines will fail; there
    // will be 12 local symbols and "def" will occur twice in the symbol table. That's because mark() includes
    // the symbol table (in this case an LST append), and rewinding past the symbol table causes the append
    // to be processed a second time by IonReader.next().
    SymbolTable symbolTable = reader.getSymbolTable();
    assertEquals(symbolTable.getSystemSymbolTable().getMaxId() + 2, reader.getSymbolTable().getMaxId());
    List<String> symbols = new ArrayList<String>(2);
    Iterator<String> iterator = symbolTable.iterateDeclaredSymbolNames();
    while (iterator.hasNext()) {
        symbols.add(iterator.next());
    }
    assertEquals(Arrays.asList("abc", "def"), symbols);
    input.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IonReader(com.amazon.ion.IonReader) ArrayList(java.util.ArrayList) SymbolTable(com.amazon.ion.SymbolTable) IonWriter(com.amazon.ion.IonWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 97 with SymbolTable

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

the class LocalSymbolTableTest method testFindSymbolTokenWhenReadOnly.

@Test
public void testFindSymbolTokenWhenReadOnly() {
    SymbolTable st = makeLocalSymtab(system(), LOCAL_SYMBOLS_ABC, ST_FRED_V2, ST_GINGER_V1);
    st.makeReadOnly();
    testFindSymbolToken(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)

Example 98 with SymbolTable

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

the class LocalSymbolTableTest method testCopyLSTWithSubstitutedImports.

// -------------------------------------------------------------------------
// Tests for _Private_DmsdkUtils.makeCopy(SymbolTable)
@Test
public void testCopyLSTWithSubstitutedImports() {
    SubstituteSymbolTable subFred2 = new SubstituteSymbolTable("fred", 2, FRED_MAX_IDS[2]);
    Symtabs.register("fred", 1, catalog());
    SymbolTable localSymtab = makeLocalSymtab(system(), EMPTY_STRING_ARRAY, subFred2);
    SymbolTable[] imports = localSymtab.getImportedTables();
    assertTrue(imports[0].isSubstitute());
    myExpectedException.expect(SubstituteSymbolTableException.class);
    // method under test
    copyLocalSymbolTable(localSymtab);
}
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 99 with SymbolTable

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

the class LocalSymbolTableTest method testCopyLSTOnImport.

@Test
public void testCopyLSTOnImport() {
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    myExpectedException.expect(IllegalArgumentException.class);
    // method under test
    copyLocalSymbolTable(fred1);
}
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 100 with SymbolTable

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

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSubsetWriterImport.

/**
 * Writer's imports subset of Reader's - no optimize.
 */
@Test
public void testOptimizedWriteValueSubsetWriterImport() throws Exception {
    SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
    byte[] source = encode(importFred2 + "fred_1 123 null");
    ir = makeReaderProxy(source);
    iw = makeWriter(fred1);
    checkWriteValueWithIncompatibleSymtab();
    checkWriteValueWithIncompatibleSymtab();
    checkWriteValueWithIncompatibleSymtab();
    iw.close();
    assertIonIteratorEquals(system().iterate(source), system().iterate(outputByteArray()));
}
Also used : SymbolTable(com.amazon.ion.SymbolTable) 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