Java Code Examples for org.apache.nifi.flowfile.FlowFile#getId()

The following examples show how to use org.apache.nifi.flowfile.FlowFile#getId() . 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 vote down vote up
@Override
public MockFlowFile merge(final Collection<FlowFile> sources, final FlowFile destination) {
    for (final FlowFile source : sources) {
        validateState(source);
    }
    validateState(destination);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (final FlowFile flowFile : sources) {
        final MockFlowFile mock = (MockFlowFile) flowFile;
        final byte[] data = mock.getData();
        try {
            baos.write(data);
        } catch (final IOException e) {
            throw new AssertionError("Failed to write to BAOS");
        }
    }

    final MockFlowFile newFlowFile = new MockFlowFile(destination.getId(), destination);
    newFlowFile.setData(baos.toByteArray());
    currentVersions.put(newFlowFile.getId(), newFlowFile);

    return newFlowFile;
}
 
Example 2
Source File: MockProcessSession.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination) {
    sources = validateState(sources);
    destination = validateState(destination);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    for (final FlowFile flowFile : sources) {
        final MockFlowFile mock = (MockFlowFile) flowFile;
        final byte[] data = mock.getData();
        try {
            baos.write(data);
        } catch (final IOException e) {
            throw new AssertionError("Failed to write to BAOS");
        }
    }

    final MockFlowFile newFlowFile = new MockFlowFile(destination.getId(), destination);
    newFlowFile.setData(baos.toByteArray());
    currentVersions.put(newFlowFile.getId(), newFlowFile);

    return newFlowFile;
}
 
Example 3
Source File: MockProcessSession.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public MockFlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) {
    sources = validateState(sources);
    destination = validateState(destination);

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        if (header != null) {
            baos.write(header);
        }

        int count = 0;
        for (final FlowFile flowFile : sources) {
            baos.write(((MockFlowFile) flowFile).getData());
            if (demarcator != null && ++count != sources.size()) {
                baos.write(demarcator);
            }
        }

        if (footer != null) {
            baos.write(footer);
        }
    } catch (final IOException e) {
        throw new AssertionError("failed to write data to BAOS");
    }

    final MockFlowFile newFlowFile = new MockFlowFile(destination.getId(), destination);
    newFlowFile.setData(baos.toByteArray());
    currentVersions.put(newFlowFile.getId(), newFlowFile);

    return newFlowFile;
}
 
Example 4
Source File: MockProcessSession.java    From nifi with Apache License 2.0 5 votes vote down vote up
public MockFlowFile unpenalize(FlowFile flowFile) {
    flowFile = validateState(flowFile);
    final MockFlowFile newFlowFile = new MockFlowFile(flowFile.getId(), flowFile);
    currentVersions.put(newFlowFile.getId(), newFlowFile);
    newFlowFile.setPenalized(false);
    penalized.remove(newFlowFile);
    return newFlowFile;
}