private List<Event> createEventList(
      ThriftEventBundle thriftEventBundle, StreamTypeHolder streamTypeHolder) {

    IndexCounter indexCounter = new IndexCounter();
    List<Event> eventList = new ArrayList<Event>(thriftEventBundle.getEventNum());
    String streamId = null;
    try {
      for (int i = 0; i < thriftEventBundle.getEventNum(); i++) {
        Event event = new Event();
        streamId = thriftEventBundle.getStringAttributeList().get(indexCounter.getStringCount());
        indexCounter.incrementStringCount();
        event.setStreamId(streamId);
        long timeStamp = thriftEventBundle.getLongAttributeList().get(indexCounter.getLongCount());
        indexCounter.incrementLongCount();
        event.setTimeStamp(timeStamp);
        AttributeType[][] attributeTypeOrder = streamTypeHolder.getDataType(streamId);
        if (attributeTypeOrder == null) {
          PrivilegedCarbonContext privilegedCarbonContext =
              PrivilegedCarbonContext.getThreadLocalCarbonContext();
          if (privilegedCarbonContext.getTenantDomain() == null) {
            privilegedCarbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
            privilegedCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
          }
          streamTypeHolder.reloadStreamTypeHolder();
          attributeTypeOrder = streamTypeHolder.getDataType(streamId);
          if (attributeTypeOrder == null) {
            throw new EventConversionException(
                "No StreamDefinition for streamId " + streamId + " present in cache ");
          }
        }
        event.setMetaData(
            this.toObjectArray(thriftEventBundle, attributeTypeOrder[0], indexCounter));
        event.setCorrelationData(
            this.toObjectArray(thriftEventBundle, attributeTypeOrder[1], indexCounter));
        event.setPayloadData(
            this.toObjectArray(thriftEventBundle, attributeTypeOrder[2], indexCounter));
        if (thriftEventBundle.isSetArbitraryDataMapMap()) {
          Map<String, String> arbitraryData = thriftEventBundle.getArbitraryDataMapMap().get(i);
          if (null != arbitraryData) {
            event.setArbitraryDataMap(arbitraryData);
          }
        }
        eventList.add(event);
      }
    } catch (RuntimeException re) {
      throw new EventConversionException(
          "Error when converting "
              + streamId
              + " of event bundle with events "
              + thriftEventBundle.getEventNum(),
          re);
    }
    return eventList;
  }
 public Object[] toObjectArray(
     ThriftEventBundle thriftEventBundle,
     AttributeType[] attributeTypeOrder,
     IndexCounter indexCounter) {
   if (attributeTypeOrder != null) {
     Object[] objects = new Object[attributeTypeOrder.length];
     for (int i = 0; i < attributeTypeOrder.length; i++) {
       switch (attributeTypeOrder[i]) {
         case INT:
           objects[i] = thriftEventBundle.getIntAttributeList().get(indexCounter.getIntCount());
           indexCounter.incrementIntCount();
           break;
         case LONG:
           objects[i] = thriftEventBundle.getLongAttributeList().get(indexCounter.getLongCount());
           indexCounter.incrementLongCount();
           break;
         case STRING:
           String stringValue =
               thriftEventBundle.getStringAttributeList().get(indexCounter.getStringCount());
           if (stringValue.equals(EventDefinitionConverterUtils.nullString)) {
             objects[i] = null;
           } else {
             objects[i] = stringValue;
           }
           indexCounter.incrementStringCount();
           break;
         case DOUBLE:
           objects[i] =
               thriftEventBundle.getDoubleAttributeList().get(indexCounter.getDoubleCount());
           indexCounter.incrementDoubleCount();
           break;
         case FLOAT:
           objects[i] =
               thriftEventBundle
                   .getDoubleAttributeList()
                   .get(indexCounter.getDoubleCount())
                   .floatValue();
           indexCounter.incrementDoubleCount();
           break;
         case BOOL:
           objects[i] = thriftEventBundle.getBoolAttributeList().get(indexCounter.getBoolCount());
           indexCounter.incrementBoolCount();
           break;
       }
     }
     return objects;
   } else {
     return null;
   }
 }