private void populateStreamEvent(ComplexEvent complexEvent, Object data, int[] toPosition) {
        if (toPosition == null) {
            // This happens when this data is not used by the query.
            return;
        }
        StreamEvent streamEvent;
        if (complexEvent instanceof StreamEvent) {
            streamEvent = (StreamEvent) complexEvent;
        } else {
            streamEvent = ((StateEvent) complexEvent).getStreamEvent(toPosition[STREAM_EVENT_CHAIN_INDEX]);
            for (int i = 0; i <= toPosition[STREAM_EVENT_INDEX_IN_CHAIN]; i++) {
                streamEvent = streamEvent.getNext();
            }
        }
        switch (toPosition[STREAM_ATTRIBUTE_TYPE_INDEX]) {
            case 0:
                streamEvent.setBeforeWindowData(data, toPosition[STREAM_ATTRIBUTE_INDEX_IN_TYPE]);
                break;
            case 1:
                streamEvent.setOnAfterWindowData(data, toPosition[STREAM_ATTRIBUTE_INDEX_IN_TYPE]);
                break;
            case 2:
                complexEvent.setOutputData(data, toPosition[STREAM_ATTRIBUTE_INDEX_IN_TYPE]);
                break;
            default:
                //will not happen
                throw new IllegalStateException("To Position cannot be :" + Arrays.toString(toPosition));
        }
    }
The populater class that populates StateEvents
modules/siddhi-core/src/main/java/io/siddhi/core/event/stream/populater/SelectiveComplexEventPopulater.java