private Event toEvent()

in flume-morphline-solr-sink/src/main/java/org/apache/flume/sink/solr/morphline/MorphlineInterceptor.java [174:203]


    private Event toEvent(Record record) {
      Map<String, String> headers = new HashMap();
      Map<String, Collection<Object>> recordMap = record.getFields().asMap();
      byte[] body = null;
      for (Map.Entry<String, Collection<Object>> entry : recordMap.entrySet()) {
        if (entry.getValue().size() > 1) {
          throw new FlumeException(getClass().getName()
              + " must not generate more than one output value per record field");
        }
        assert entry.getValue().size() != 0; // guava guarantees that
        Object firstValue = entry.getValue().iterator().next();
        if (Fields.ATTACHMENT_BODY.equals(entry.getKey())) {
          if (firstValue instanceof byte[]) {
            body = (byte[]) firstValue;
          } else if (firstValue instanceof InputStream) {
            try {
              body = ByteStreams.toByteArray((InputStream) firstValue);
            } catch (IOException e) {
              throw new FlumeException(e);
            }
          } else {
            throw new FlumeException(getClass().getName()
                + " must non generate attachments that are not a byte[] or InputStream");
          }
        } else {
          headers.put(entry.getKey(), firstValue.toString());
        }
      }
      return EventBuilder.withBody(body, headers);
    }