David,

In this case, since you want to keep the original intact, you will need to 
create a 'child' flowfile to write to.
You do this with ProcessSession.create(FlowFile)

So you will have code that looks something like this:

final FlowFile original = session.get();
if (original == null) {
  return;
}

// create a new 'child' FlowFile. The framework will automatically handle
// the provenance information so that 'parsed' is forked from 'original'.
FlowFile parsed = session.create(original);

// Get an OutputStream for the 'parsed' FlowFile
parsed = session.write(parsed, new OutputStreamCallback() {
    public void process(OutputStream parsedOut) {

        // Get an InputStream for the original
        session.read(original, new InputStreamCallback() {
            public void process(InputStream originalIn) {
                // read from original FlowFile via originalIn
                // write to new FlowFile via parsedOut
            }
        });

    }
});

Does this give you what you need? If anything is still unclear, let us know!

Thanks
-Mark

----------------------------------------
> Date: Sat, 15 Aug 2015 10:04:54 +0100
> From: davidrsm...@btinternet.com
> Subject: Writing to a flowfile
> To: dev@nifi.apache.org
>
>
> Hi
>
> I'm writing a processor which parses a file, I want the parsed file to go to 
> relationship parsed, and the original file to go to relationship original, if 
> the parse was ok.
> If the parse fails I want the original file to go to relationship failure.
>
> I have an inner class which contains a callback which does the parsing. The 
> callback is called from the onTrigger method.
> My problem is that I want to read from my original flowFile and write to a 
> new flowFile, but it always seems to write to the original flowfile.
> How do I direct my bufferedwriter to my new flowfile?
>
> Many thanks
> Dave
>
> Sent from Yahoo! Mail on Android
>
                                          

Reply via email to