Exemple #1
0
    @Override
    protected boolean doProcess(Record inputRecord) {
      //
      // Preconditions.checkState(ReadAvroBuilder.AVRO_MEMORY_MIME_TYPE.equals(inputRecord.getFirstValue(Fields.ATTACHMENT_MIME_TYPE)));
      GenericContainer datum = (GenericContainer) inputRecord.getFirstValue(Fields.ATTACHMENT_BODY);
      Preconditions.checkNotNull(datum);
      Preconditions.checkNotNull(datum.getSchema());
      Record outputRecord = inputRecord.copy();

      extractTree(datum, datum.getSchema(), outputRecord, outputFieldPrefix);

      // pass record to next command in chain:
      return getChild().process(outputRecord);
    }
    @Override
    protected boolean doProcess(Record inputRecord, InputStream stream) throws IOException {
      if (counter++ % 8192 == 0) {
        clob = new StringBuilder(); // periodically gc memory from large outlier strings
      }
      incrementNumRecords();
      Charset detectedCharset = detectCharset(inputRecord, charset);
      Reader reader = new InputStreamReader(stream, detectedCharset);
      clob.setLength(0);
      int len;
      while ((len = reader.read(buffer)) >= 0) {
        clob.append(buffer, 0, len);
      }
      Record outputRecord = inputRecord.copy();
      removeAttachments(outputRecord);
      outputRecord.replaceValues(Fields.MESSAGE, clob.toString());

      // pass record to next command in chain:
      return getChild().process(outputRecord);
    }