Java Code Examples for org.apache.nifi.processor.io.OutputStreamCallback#process()
The following examples show how to use
org.apache.nifi.processor.io.OutputStreamCallback#process() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockProcessSession.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public FlowFile append(final FlowFile flowFile, final OutputStreamCallback callback) { validateState(flowFile); if (callback == null || flowFile == null) { throw new IllegalArgumentException("argument cannot be null"); } if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final MockFlowFile mock = (MockFlowFile) flowFile; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { baos.write(mock.getData()); callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } final MockFlowFile newFlowFile = new MockFlowFile(mock.getId(), flowFile); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.setData(baos.toByteArray()); return newFlowFile; }
Example 2
Source File: MockProcessSession.java From nifi with Apache License 2.0 | 6 votes |
@Override public FlowFile append(FlowFile flowFile, final OutputStreamCallback callback) { if (callback == null || flowFile == null) { throw new IllegalArgumentException("argument cannot be null"); } final MockFlowFile mock = validateState(flowFile); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { baos.write(mock.getData()); callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } final MockFlowFile newFlowFile = new MockFlowFile(mock.getId(), flowFile); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.setData(baos.toByteArray()); return newFlowFile; }
Example 3
Source File: StatelessProcessSession.java From nifi with Apache License 2.0 | 6 votes |
@Override public StatelessFlowFile write(FlowFile flowFile, final OutputStreamCallback callback) { flowFile = validateState(flowFile); if (callback == null) { throw new IllegalArgumentException("callback cannot be null"); } if (!(flowFile instanceof StatelessFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } final StatelessFlowFile newFlowFile = new StatelessFlowFile((StatelessFlowFile) flowFile, this.materializeContent); newFlowFile.setData(baos.toByteArray()); currentVersions.put(newFlowFile.getId(), newFlowFile); return newFlowFile; }
Example 4
Source File: StatelessProcessSession.java From nifi with Apache License 2.0 | 6 votes |
@Override public FlowFile append(FlowFile flowFile, final OutputStreamCallback callback) { if (callback == null || flowFile == null) { throw new IllegalArgumentException("argument cannot be null"); } final StatelessFlowFile validatedFlowFile = validateState(flowFile); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } final StatelessFlowFile newFlowFile = new StatelessFlowFile(validatedFlowFile, this.materializeContent); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.addData(baos.toByteArray()); return newFlowFile; }
Example 5
Source File: MockProcessSession.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override public MockFlowFile write(final FlowFile flowFile, final OutputStreamCallback callback) { validateState(flowFile); if (callback == null || flowFile == null) { throw new IllegalArgumentException("argument cannot be null"); } if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final MockFlowFile mock = (MockFlowFile) flowFile; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); recursionSet.add(flowFile); try { callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } finally { recursionSet.remove(flowFile); } final MockFlowFile newFlowFile = new MockFlowFile(mock.getId(), flowFile); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.setData(baos.toByteArray()); return newFlowFile; }
Example 6
Source File: MockProcessSession.java From nifi with Apache License 2.0 | 5 votes |
@Override public MockFlowFile write(FlowFile flowFile, final OutputStreamCallback callback) { flowFile = validateState(flowFile); if (callback == null || flowFile == null) { throw new IllegalArgumentException("argument cannot be null"); } if (!(flowFile instanceof MockFlowFile)) { throw new IllegalArgumentException("Cannot export a flow file that I did not create"); } final MockFlowFile mock = (MockFlowFile) flowFile; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeRecursionSet.add(flowFile); try { callback.process(baos); } catch (final IOException e) { throw new ProcessException(e.toString(), e); } finally { writeRecursionSet.remove(flowFile); } final MockFlowFile newFlowFile = new MockFlowFile(mock.getId(), flowFile); currentVersions.put(newFlowFile.getId(), newFlowFile); newFlowFile.setData(baos.toByteArray()); return newFlowFile; }
Example 7
Source File: StandardProcessSession.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public FlowFile write(final FlowFile source, final OutputStreamCallback writer) { validateRecordState(source); final StandardRepositoryRecord record = records.get(source); long writtenToFlowFile = 0L; ContentClaim newClaim = null; try { newClaim = claimCache.getContentClaim(); claimLog.debug("Creating ContentClaim {} for 'write' for {}", newClaim, source); ensureNotAppending(newClaim); try (final OutputStream stream = claimCache.write(newClaim); final OutputStream disableOnClose = new DisableOnCloseOutputStream(stream); final ByteCountingOutputStream countingOut = new ByteCountingOutputStream(disableOnClose)) { try { recursionSet.add(source); writer.process(new FlowFileAccessOutputStream(countingOut, source)); } finally { writtenToFlowFile = countingOut.getBytesWritten(); bytesWritten += countingOut.getBytesWritten(); } } finally { recursionSet.remove(source); } } catch (final ContentNotFoundException nfe) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim); handleContentNotFound(nfe, record); } catch (final FlowFileAccessException ffae) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim); throw ffae; } catch (final IOException ioe) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim); throw new ProcessException("IOException thrown from " + connectableDescription + ": " + ioe.toString(), ioe); } catch (final Throwable t) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim); throw t; } removeTemporaryClaim(record); final FlowFileRecord newFile = new StandardFlowFileRecord.Builder() .fromFlowFile(record.getCurrent()) .contentClaim(newClaim) .contentClaimOffset(Math.max(0, newClaim.getLength() - writtenToFlowFile)) .size(writtenToFlowFile) .build(); record.setWorking(newFile); return newFile; }
Example 8
Source File: StandardProcessSession.java From nifi with Apache License 2.0 | 4 votes |
@Override public FlowFile write(FlowFile source, final OutputStreamCallback writer) { verifyTaskActive(); source = validateRecordState(source); final StandardRepositoryRecord record = getRecord(source); long writtenToFlowFile = 0L; ContentClaim newClaim = null; try { newClaim = claimCache.getContentClaim(); claimLog.debug("Creating ContentClaim {} for 'write' for {}", newClaim, source); ensureNotAppending(newClaim); try (final OutputStream stream = claimCache.write(newClaim); final OutputStream disableOnClose = new DisableOnCloseOutputStream(stream); final ByteCountingOutputStream countingOut = new ByteCountingOutputStream(disableOnClose)) { try { writeRecursionSet.add(source); final OutputStream ffaos = new FlowFileAccessOutputStream(countingOut, source); writer.process(createTaskTerminationStream(ffaos)); } finally { writtenToFlowFile = countingOut.getBytesWritten(); bytesWritten += countingOut.getBytesWritten(); } } finally { writeRecursionSet.remove(source); } } catch (final ContentNotFoundException nfe) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim, record); handleContentNotFound(nfe, record); } catch (final FlowFileAccessException ffae) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim, record); throw ffae; } catch (final IOException ioe) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim, record); throw new ProcessException("IOException thrown from " + connectableDescription + ": " + ioe.toString(), ioe); } catch (final Throwable t) { resetWriteClaims(); // need to reset write claim before we can remove the claim destroyContent(newClaim, record); throw t; } removeTemporaryClaim(record); final FlowFileRecord newFile = new StandardFlowFileRecord.Builder() .fromFlowFile(record.getCurrent()) .contentClaim(newClaim) .contentClaimOffset(Math.max(0, newClaim.getLength() - writtenToFlowFile)) .size(writtenToFlowFile) .build(); record.setWorking(newFile); return newFile; }