Package org.apache.nifi.util
Class FlowFilePackagerV2
java.lang.Object
org.apache.nifi.util.FlowFilePackagerV2
- All Implemented Interfaces:
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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate final byte[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcopy(InputStream in, OutputStream out) voidpackageFlowFile(InputStream in, OutputStream out, Map<String, String> attributes, long fileSize) private voidwriteFieldLength(OutputStream out, int numBytes) private voidwriteLong(OutputStream out, long val) private voidwriteString(String val, OutputStream out)
-
Field Details
-
MAX_VALUE_2_BYTES
private static final int MAX_VALUE_2_BYTES- See Also:
-
writeBuffer
private final byte[] writeBuffer
-
-
Constructor Details
-
FlowFilePackagerV2
public FlowFilePackagerV2()
-
-
Method Details
-
packageFlowFile
public void packageFlowFile(InputStream in, OutputStream out, Map<String, String> attributes, long fileSize) throws IOException- Specified by:
packageFlowFilein interfaceFlowFilePackager- Throws:
IOException
-
copy
- Throws:
IOException
-
writeString
- Throws:
IOException
-
writeFieldLength
- Throws:
IOException
-
writeLong
- Throws:
IOException
-