Class FlowFilePackagerV2

java.lang.Object
org.apache.nifi.util.FlowFilePackagerV2
All Implemented Interfaces:
FlowFilePackager

public class FlowFilePackagerV2 extends Object implements FlowFilePackager

Packages a FlowFile, including both its content and its attributes into a single file that is stream-friendly. The encoding scheme is as such:

 Length Field : indicates the number of Flow File Attributes in the stream
 1 to N times (N=number of Flow File Attributes):
      String Field : Flow File Attribute key name
      String Field : Flow File Attribute value
 Long : 8 bytes indicating the length of the Flow File content
 Content : The next M bytes are the content of the Flow File.
 
 Encoding of String Field is as follows:
      Length Field : indicates the length of the String
      1 to N bytes (N=String length, determined by previous field, as described above) : The UTF-8 encoded string value.
 
 Encoding of Length Field is as follows:
      First 2 bytes: Indicate length. If both bytes = 255, this is a special value indicating that the length is
                     greater than or equal to 65536 bytes; therefore, the next 4 bytes will indicate the actual length.
 

Note: All byte-order encoding is Network Byte Order (Most Significant Byte first)

The following example shows the bytes expected if we were to encode a FlowFile containing the following attributes where the content is the text "Hello World!":

Attributes:

 +-------+-------+
 | Key   + Value |
 + --------------+
 | A     | a     |
 + --------------+
 | B     | b     |
 + --------------+
 
Content:
Hello World!

Packaged Byte Encoding (In Hexadecimal Form):

 00 02 00 01 41 00 01 61
 00 01 42 00 01 62 00 00
 00 00 00 00 00 0C 48 65
 6C 6C 6F 20 57 6F 72 6C
 64 21