in plc4j/integrations/apache-nifi/nifi-plc4x-processors/src/main/java/org/apache/plc4x/nifi/record/RecordPlc4xWriter.java [78:108]
public long writePlcReadResponse(PlcReadResponse response, OutputStream outputStream, ComponentLog logger,
RecordSchema recordSchema, FlowFile originalFlowFile, String timestampFieldName) throws Exception {
if (fullRecordSet == null) {
fullRecordSet = new Plc4xReadResponseRecordSetWithCallback(response, recordSchema, timestampFieldName);
writeSchema = recordSetWriterFactory.getSchema(originalAttributes, fullRecordSet.getSchema());
}
RecordSetWriter resultSetWriter = null;
try {
if (originalFlowFile != null) {
try {
resultSetWriter = recordSetWriterFactory.createWriter(logger, writeSchema, outputStream, originalFlowFile);
} catch (final Exception e) {
throw new IOException(e);
}
} else {
resultSetWriter = recordSetWriterFactory.createWriter(logger, writeSchema, outputStream, Collections.emptyMap());
}
writeResultRef.set(resultSetWriter.write(fullRecordSet));
if (mimeType == null) {
mimeType = resultSetWriter.getMimeType();
}
return writeResultRef.get().getRecordCount();
} finally {
if (resultSetWriter != null) {
resultSetWriter.close();
}
}
}