use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class BinaryWriterWithLocalSymtabsTest method testConstructionWithLocalSymbolsAndOneImports.
@Test
public void testConstructionWithLocalSymbolsAndOneImports() throws Exception {
SymbolTable fred1 = Symtabs.register("fred", 1, catalog());
checkConstructionWithLocalSymbolsAndImports(LOCAL_SYMBOLS_ABC, fred1);
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryIncremental method pop_passed_symbol_table.
@Override
public SymbolTable pop_passed_symbol_table() {
SymbolTable currentSymbolTable = getSymbolTable();
if (currentSymbolTable == symbolTableLastTransferred) {
// be returned twice.
return null;
}
symbolTableLastTransferred = currentSymbolTable;
return symbolTableLastTransferred;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonJavaCli method ionStreamToEventStream.
private static void ionStreamToEventStream(IonReader ionReader, CommandType commandType, SymbolTable curTable, ReadContext readContext) throws IOException {
if (ionReader.getType() == null)
return;
do {
if (ionReader.isNullValue()) {
IonValue value = ION_SYSTEM.newValue(ionReader);
value.clearTypeAnnotations();
readContext.getEventStream().add(new Event(EventType.SCALAR, ionReader.getType(), ionReader.getFieldNameSymbol(), ionReader.getTypeAnnotationSymbols(), value, null, ionReader.getDepth()));
continue;
}
if (!isSameSymbolTable(ionReader.getSymbolTable(), curTable)) {
curTable = ionReader.getSymbolTable();
ImportDescriptor[] imports = symbolTableToImports(curTable.getImportedTables());
if (commandType != CommandType.COMPARE) {
readContext.getEventStream().add(new Event(EventType.SYMBOL_TABLE, null, null, null, null, imports, 0));
}
}
if (isEmbeddedStream(ionReader)) {
// get current Ion type and depth
IonType curType = ionReader.getType();
int curDepth = ionReader.getDepth();
// write a Container_Start event and step in
readContext.getEventStream().add(ionStreamToEvent(ionReader));
ionReader.stepIn();
while (ionReader.next() != null) {
if (ionReader.getType() != IonType.STRING) {
throw new IonException("Elements of embedded streams sets must be strings.");
}
String stream = ionReader.stringValue();
try (IonReader tempIonReader = IonReaderBuilder.standard().build(stream)) {
SymbolTable symbolTable = tempIonReader.getSymbolTable();
while (tempIonReader.next() != null) {
ionStreamToEventStream(tempIonReader, commandType, symbolTable, readContext);
}
}
readContext.getEventStream().add(new Event(EventType.STREAM_END, null, null, null, null, null, 0));
}
// write a Container_End event and step out
readContext.getEventStream().add(new Event(EventType.CONTAINER_END, curType, null, null, null, null, curDepth));
ionReader.stepOut();
} else if (IonType.isContainer(ionReader.getType())) {
// get current Ion type and depth
IonType curType = ionReader.getType();
int curDepth = ionReader.getDepth();
// write a Container_Start event and step in
readContext.getEventStream().add(ionStreamToEvent(ionReader));
ionReader.stepIn();
// recursive call
ionReader.next();
ionStreamToEventStream(ionReader, commandType, curTable, readContext);
// write a Container_End event and step out
readContext.getEventStream().add(new Event(EventType.CONTAINER_END, curType, null, null, null, null, curDepth));
ionReader.stepOut();
} else {
readContext.getEventStream().add(ionStreamToEvent(ionReader));
}
} while (ionReader.next() != null);
;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonJavaCli method getEventStream.
private static void getEventStream(IonReader ionReader, CommandType commandType, ReadContext readContext) throws IOException {
SymbolTable curTable = ionReader.getSymbolTable();
boolean isEventStream = isEventStream(ionReader);
if (isEventStream) {
readContext.setState(ErrorType.WRITE);
while (ionReader.next() != null) {
Event event = eventStreamToEvent(ionReader);
if (event.getEventType() == EventType.SYMBOL_TABLE && commandType == CommandType.COMPARE) {
continue;
}
readContext.getEventStream().add(event);
}
} else {
readContext.setState(ErrorType.READ);
ionStreamToEventStream(ionReader, commandType, curTable, readContext);
readContext.getEventStream().add(new Event(EventType.STREAM_END, null, null, null, null, null, 0));
}
if (commandType == CommandType.PROCESS) {
validateEventStream(readContext.getEventStream());
}
return;
}
use of com.amazon.ion.SymbolTable in project ion-java by amzn.
the class IonReaderBinaryUserX method pop_passed_symbol_table.
@Override
public SymbolTable pop_passed_symbol_table() {
if (_symbol_table_top <= 0) {
return null;
}
_symbol_table_top--;
SymbolTable symbols = _symbol_table_stack[_symbol_table_top];
_symbol_table_stack[_symbol_table_top] = null;
return symbols;
}
Aggregations