use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class TextWriterTest method testLstMinimizing.
@Test
public void testLstMinimizing() throws Exception {
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
IonBinaryWriter binaryWriter = system().newBinaryWriter(fred1);
binaryWriter.writeSymbol("fred_1");
binaryWriter.writeSymbol("ginger");
binaryWriter.finish();
byte[] binaryData = binaryWriter.getBytes();
options = IonTextWriterBuilder.standard();
// TODO User reader still transfers local symtabs!
IonReader binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
String ionText = outputString();
assertEquals("$ion_symbol_table::{imports:[{name:\"fred\",version:1,max_id:2}]," + "symbols:[\"ginger\"]} " + "fred_1 ginger", ionText);
options.setLstMinimizing(LstMinimizing.LOCALS);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("$ion_symbol_table::{imports:[{name:\"fred\",version:1,max_id:2}]} " + "fred_1 ginger", ionText);
options.setLstMinimizing(LstMinimizing.EVERYTHING);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("$ion_1_0 fred_1 ginger", ionText);
options.setInitialIvmHandling(SUPPRESS);
binaryReader = system().newReader(binaryData);
iw = makeWriter();
iw.writeValues(binaryReader);
ionText = outputString();
assertEquals("fred_1 ginger", ionText);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class ValueWriterTest method testWriteValuesWithSymtabIntoContainer.
// TODO more thorough testing that you can't output from DOM w/ bad text
@Test
public void testWriteValuesWithSymtabIntoContainer() throws Exception {
myOutputInList = true;
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.writeValues(r);
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, systemMaxId() + Symtabs.FRED_MAX_IDS[1] + 1, s);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableSnapshotImplementsBasicMethods.
@Test
public void symbolTableSnapshotImplementsBasicMethods() throws Exception {
IonReaderBinaryIncremental reader = readerFor("'abc'");
reader.next();
SymbolTable symbolTable = reader.getSymbolTable();
assertNull(symbolTable.getName());
assertEquals(0, symbolTable.getVersion());
assertTrue(symbolTable.isLocalTable());
assertTrue(symbolTable.isReadOnly());
assertFalse(symbolTable.isSharedTable());
assertFalse(symbolTable.isSystemTable());
assertFalse(symbolTable.isSubstitute());
symbolTable.makeReadOnly();
assertEquals(10, symbolTable.getMaxId());
assertEquals("abc", symbolTable.findKnownSymbol(10));
assertNull(symbolTable.findKnownSymbol(symbolTable.getMaxId() + 1));
thrown.expect(IllegalArgumentException.class);
symbolTable.findKnownSymbol(-1);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method nonStringInSymbolsListCreatesNullSlot.
@Test
public void nonStringInSymbolsListCreatesNullSlot() throws Exception {
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString(null);
writer.writeString("abc");
writer.writeInt(123);
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
}
});
assertEquals(IonType.SYMBOL, reader.next());
SymbolToken symbolValue = reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(0, symbolValue.getSid());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = reader.symbolValue();
assertEquals("abc", symbolValue.getText());
assertEquals(IonType.SYMBOL, reader.next());
symbolValue = reader.symbolValue();
assertNull(symbolValue.getText());
assertEquals(0, symbolValue.getSid());
reader.close();
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithSymbolsThenImports.
@Test
public void symbolTableWithSymbolsThenImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertNull(reader.next());
reader.close();
}
Aggregations