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();
}
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);
}
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);
}
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);
}
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()));
}
Aggregations