Created 11-10-2016 01:19 PM
I have a requirement where I will have to decide the flow based on the record header.
Since the file is huge, I don't want to waste time reading the entire file where only one record is enough.
Is there a way I can achieve this.
Created 11-10-2016 05:44 PM
def flowFile = session.get() if(!flowFile) return def header = '' session.read(flowFile, { inStream -> header = new BufferedReader(new InputStreamReader(inStream)).readLine() } as InputStreamCallback) flowFile = session.putAttribute(flowFile, 'header', header) session.transfer(flowFile, REL_SUCCESS)
This puts the first line in an attribute called 'header', which you can use with RouteOnAttribute to decide where to send the flow. Note that this script doesn't do error handling, but you could put a try/catch around the session.read to session.transfer, the catch could route the flow file to REL_FAILURE.
Created 11-10-2016 05:44 PM
def flowFile = session.get() if(!flowFile) return def header = '' session.read(flowFile, { inStream -> header = new BufferedReader(new InputStreamReader(inStream)).readLine() } as InputStreamCallback) flowFile = session.putAttribute(flowFile, 'header', header) session.transfer(flowFile, REL_SUCCESS)
This puts the first line in an attribute called 'header', which you can use with RouteOnAttribute to decide where to send the flow. Note that this script doesn't do error handling, but you could put a try/catch around the session.read to session.transfer, the catch could route the flow file to REL_FAILURE.