Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Nifi + Groovy + Apache POI for excel in outputStream

avatar
New Contributor

Hi everybody,

i'm new to Nifi, and i try to understand how the in/out streams works in groovy.

 

I've created one processor to generate flowfile, one to run a groovy script and a third one to putfile.

 

I've tried many many things but for now my groovy script (not working) look like this:

 

 

 

 

import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.xssf.usermodel.*
import org.apache.poi.ss.util.*
import org.apache.poi.ss.usermodel.*
import org.apache.poi.hssf.extractor.*
import java.nio.charset.*
import java.io.*

def flowFile = session.get()

if(!flowFile) return

flowFile = session.write(flowFile, {inputStream, outputStream ->
    try {

FileOutputStream out = new FileOutputStream("workbook.xls");
outputStream.write(out);
out.close();
//is not working.

// def record = "toto"
// outputStream.write(record.getBytes(StandardCharsets.UTF_8))
//is working and giving me a txt file with toto in it.

    } catch(e) {
     log.error("Error during processing", e)
     session.transfer(flowFile, REL_FAILURE)
    }
} as StreamCallback)

session.transfer(flowFile, REL_SUCCESS)

 

 

 

 
the error i get is : 
errors2.png
It says to me that the ProcessSession.write(FlowFile) has not been closed.
 
When i do outpustream.write of a string, it works, but with a excel file it doesn't work
At this point i really don't know what i'm missing.
 
My modules are well imported and class path had been setup.
 
I looked all over the internet but there is no ressource about writing an excel file in the output stream of nifi.
I 'm open to any other way to treat this problem.
Thanks!
1 REPLY 1

avatar
Contributor

Hi @ollie_  did you find a solution ?