Member since
09-28-2022
2
Posts
0
Kudos Received
0
Solutions
09-29-2022
05:04 AM
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 : 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!
... View more
Labels:
- Labels:
-
Apache NiFi
09-28-2022
02:03 AM
Hi! and thank you for this great explanation. I am trying to read (and write) on a existing excel file (from getfile processor) and export it to the outpustream to send it to another processor (very important to keep the existing file because there is some vba macro on it), but i can't succeed to do that. here is my very basic code for the moment : // import org.apache.commons.io.IOUtils import java.nio.charset.* // import java.text.SimpleDateFormat import java.io.* 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.* def flowFile = session.get() if(!flowFile) return flowFile = session.write(flowFile, {inputStream, outputStream -> try { inputStream.writeTo(outputStream) // i tried also outputStream.write(inputStream) //i tried also to retrieve the excel file with: //Workbook wb = WorkbookFactory.create(inputStream) //and write with : outputStream.write(wb) } catch(e) { log.error("Error during processing", e) session.transfer(flowFile, REL_FAILURE) } } as StreamCallback) session.transfer(flowFile, REL_SUCCESS) here is the error i got : At this point i don't know what to do. Can anybody help me?
... View more