<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to read only the header from a flowfile in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-read-only-the-header-from-a-flowfile/m-p/171759#M45868</link>
    <description>You can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt; with Groovy and the following script (assuming your input is newline-delimited):
&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return	
def header = ''
session.read(flowFile, { inStream -&amp;gt; 
   header = new BufferedReader(new InputStreamReader(inStream)).readLine()
} as InputStreamCallback)
flowFile = session.putAttribute(flowFile, 'header', header)
session.transfer(flowFile, REL_SUCCESS)
&lt;/PRE&gt;&lt;P&gt;This puts the first line in an attribute called 'header', which you can use with &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.RouteOnAttribute/index.html"&gt;RouteOnAttribute&lt;/A&gt; 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.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Nov 2016 01:44:24 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2016-11-11T01:44:24Z</dc:date>
    <item>
      <title>How to read only the header from a flowfile</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-read-only-the-header-from-a-flowfile/m-p/171758#M45867</link>
      <description>&lt;P&gt;I have a requirement where I will have to decide the flow based on the record header. &lt;/P&gt;&lt;P&gt;Since the file is huge, I don't want to waste time reading the entire file where only one record is enough.&lt;/P&gt;&lt;P&gt;Is there a way I can achieve this.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 21:19:06 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-read-only-the-header-from-a-flowfile/m-p/171758#M45867</guid>
      <dc:creator>rbalakrishnantc</dc:creator>
      <dc:date>2016-11-10T21:19:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to read only the header from a flowfile</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-read-only-the-header-from-a-flowfile/m-p/171759#M45868</link>
      <description>You can use &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.script.ExecuteScript/index.html"&gt;ExecuteScript&lt;/A&gt; with Groovy and the following script (assuming your input is newline-delimited):
&lt;PRE&gt;def flowFile = session.get()
if(!flowFile) return	
def header = ''
session.read(flowFile, { inStream -&amp;gt; 
   header = new BufferedReader(new InputStreamReader(inStream)).readLine()
} as InputStreamCallback)
flowFile = session.putAttribute(flowFile, 'header', header)
session.transfer(flowFile, REL_SUCCESS)
&lt;/PRE&gt;&lt;P&gt;This puts the first line in an attribute called 'header', which you can use with &lt;A target="_blank" href="https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.RouteOnAttribute/index.html"&gt;RouteOnAttribute&lt;/A&gt; 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.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 01:44:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-read-only-the-header-from-a-flowfile/m-p/171759#M45868</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2016-11-11T01:44:24Z</dc:date>
    </item>
  </channel>
</rss>

