Skip to content

Instantly share code, notes, and snippets.

Last active April 13, 2023 11:20
  • Star 12 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ijokarumawak/1df6d34cd1b2861eb6b7432ee7245ccd to your computer and use it in GitHub Desktop.
Example Python script to use from NiFi ExecuteScript processor which reads the first line from an incoming flow file.
from org.apache.nifi.processors.script import ExecuteScript
from import InputStreamCallback
from import BufferedReader, InputStreamReader
class ReadFirstLine(InputStreamCallback) :
__line = None;
def __init__(self) :
def getLine(self) :
return self.__line
def process(self, input) :
try :
reader = InputStreamReader(input)
bufferedReader = BufferedReader(reader)
self.__line = bufferedReader.readLine()
except :
print "Exception in Reader:"
print '-' * 60
print '-' * 60
finally :
if bufferedReader is not None :
if reader is not None :
flowFile = session.get()
if flowFile is not None :
reader = ReadFirstLine(), reader)
flowFile = session.putAttribute(flowFile, "from-content", reader.getLine())
session.transfer(flowFile, ExecuteScript.REL_SUCCESS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment