streamsets / tutorials

StreamSets Tutorials
Apache License 2.0
348 stars 192 forks source link

tutorial-processor #25

Closed ajbd2106 closed 8 years ago

ajbd2106 commented 8 years ago

It's throwing Nullpointerexception in test TestSampleProcessor while compiling code. It's working fine with the below code in

for (String fieldPath : record.getEscapedFieldPaths()) {
      Field field = record.get(fieldPath);
      if (field.getType() == Field.Type.STRING) {
        String reversed = (new StringBuilder(field.getValueAsString())).reverse().toString();
        record.set(fieldPath + ".reversed", Field.create(reversed));
      }
    }

But while writing code for whole file transfer throwing Nullpointerexception.

FileRef fileRef = record.get("/fileRef").getValueAsFileRef();
    Metadata metadata;
    try {
      metadata = ImageMetadataReader.readMetadata(fileRef.createInputStream(getContext(), InputStream.class));
    } catch (ImageProcessingException | IOException e) {
      String filename = record.get("/fileInfo/filename").getValueAsString();
      LOG.info("Exception getting metadata from {}", filename, e);
      throw new OnRecordErrorException(record, Errors.SAMPLE_02, e);
    }

    // A Metadata object contains multiple Directory objects
    for (Directory directory : metadata.getDirectories()) {
      // Each Directory stores values in Tag objects
      for (Tag tag : directory.getTags()) {
        LOG.info("TAG: {}", tag);
      }
      // Each Directory may also contain error messages
      if (directory.hasErrors()) {
        for (String error : directory.getErrors()) {
          LOG.info("ERROR: {}", error);
        }
      }
    }
metadaddy commented 8 years ago

Can you post a stack trace, @ashish21198?

metadaddy commented 8 years ago

Resolved over Slack - file is compressed - metadata library throws exception.