Search in sources :

Example 6 with EventType

use of com.amazon.tools.events.EventType in project ion-java by amzn.

the class IonJavaCli method ionStreamToEvent.

private static Event ionStreamToEvent(IonReader ionReader) throws IllegalStateException {
    if (ionReader.getType() == null)
        throw new IllegalStateException("Can't convert ionReader null type to Event");
    IonType ionType = ionReader.getType();
    SymbolToken fieldName = ionReader.getFieldNameSymbol();
    SymbolToken[] annotations = ionReader.getTypeAnnotationSymbols();
    int depth = ionReader.getDepth();
    ImportDescriptor[] imports = null;
    EventType eventType;
    IonValue value = null;
    if (IonType.isContainer(ionType)) {
        eventType = EventType.CONTAINER_START;
    } else {
        eventType = EventType.SCALAR;
        value = ION_SYSTEM.newValue(ionReader);
        value.clearTypeAnnotations();
        if (isIonVersionMarker(value.toString())) {
            value.setTypeAnnotationSymbols(_Private_Utils.newSymbolToken("$ion_user_value", 0));
        }
    }
    return new Event(eventType, ionType, fieldName, annotations, value, imports, depth);
}
Also used : IonValue(com.amazon.ion.IonValue) IonType(com.amazon.ion.IonType) SymbolToken(com.amazon.ion.SymbolToken) EventType(com.amazon.tools.events.EventType) Event(com.amazon.tools.events.Event) ImportDescriptor(com.amazon.tools.events.ImportDescriptor)

Example 7 with EventType

use of com.amazon.tools.events.EventType in project ion-java by amzn.

the class IonJavaCli method parseStruct.

private static IonStruct parseStruct(ContainerContext containerContext, CompareContext compareContext, int end, boolean isFirst) {
    Event initEvent = isFirst ? compareContext.getEventStreamFirst().get(containerContext.getIndex()) : compareContext.getEventStreamSecond().get(containerContext.getIndex());
    if (initEvent.getEventType() != EventType.CONTAINER_START || initEvent.getIonType() != IonType.STRUCT) {
        return null;
    }
    IonStruct ionStruct = ION_SYSTEM.newEmptyStruct();
    while (containerContext.increaseIndex() < end) {
        Event event = isFirst ? compareContext.getEventStreamFirst().get(containerContext.getIndex()) : compareContext.getEventStreamSecond().get(containerContext.getIndex());
        EventType eventType = event.getEventType();
        if (eventType == EventType.CONTAINER_START) {
            switch(event.getIonType()) {
                case LIST:
                    ionStruct.add(event.getFieldName(), parseSequence(containerContext, compareContext, end, isFirst, ION_SYSTEM.newEmptyList()));
                    break;
                case STRUCT:
                    ionStruct.add(event.getFieldName(), parseStruct(containerContext, compareContext, end, isFirst));
                    break;
                case SEXP:
                    ionStruct.add(event.getFieldName(), parseSequence(containerContext, compareContext, end, isFirst, ION_SYSTEM.newEmptySexp()));
                    break;
            }
        } else if (eventType == EventType.CONTAINER_END) {
            break;
        } else if (eventType == EventType.STREAM_END) {
            throw new IonException("Invalid struct: eventStream ends without CONTAINER_END");
        } else {
            IonValue cloneValue = event.getValue().clone();
            cloneValue.setTypeAnnotationSymbols(event.getAnnotations());
            ionStruct.add(event.getFieldName(), cloneValue);
        }
    }
    return ionStruct;
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) EventType(com.amazon.tools.events.EventType) IonException(com.amazon.ion.IonException) Event(com.amazon.tools.events.Event)

Aggregations

EventType (com.amazon.tools.events.EventType)7 Event (com.amazon.tools.events.Event)6 IonException (com.amazon.ion.IonException)4 IonValue (com.amazon.ion.IonValue)4 SymbolToken (com.amazon.ion.SymbolToken)3 IonStruct (com.amazon.ion.IonStruct)2 IonType (com.amazon.ion.IonType)2 ImportDescriptor (com.amazon.tools.events.ImportDescriptor)2 ArrayList (java.util.ArrayList)2 IonTimestamp (com.amazon.ion.IonTimestamp)1