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:
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
| Modifier and Type | Field and Description |
|---|---|
private static int |
MAX_VALUE_2_BYTES |
private byte[] |
writeBuffer |
| Constructor and Description |
|---|
FlowFilePackagerV2() |
| Modifier and Type | Method and Description |
|---|---|
private void |
copy(InputStream in,
OutputStream out) |
void |
packageFlowFile(InputStream in,
OutputStream out,
Map<String,String> attributes,
long fileSize) |
private void |
writeFieldLength(OutputStream out,
int numBytes) |
private void |
writeLong(OutputStream out,
long val) |
private void |
writeString(String val,
OutputStream out) |
private static final int MAX_VALUE_2_BYTES
private final byte[] writeBuffer
public void packageFlowFile(InputStream in, OutputStream out, Map<String,String> attributes, long fileSize) throws IOException
packageFlowFile in interface FlowFilePackagerIOExceptionprivate void copy(InputStream in, OutputStream out) throws IOException
IOExceptionprivate void writeString(String val, OutputStream out) throws IOException
IOExceptionprivate void writeFieldLength(OutputStream out, int numBytes) throws IOException
IOExceptionprivate void writeLong(OutputStream out, long val) throws IOException
IOExceptionCopyright © 2015 Apache NiFi Project. All rights reserved.