Member since
05-25-2017
6
Posts
2
Kudos Received
0
Solutions
05-25-2017
06:12 PM
1 Kudo
Hey guys, I know this is an old post and the original question was only about the first 16 bits hex dump. However, since I came across this post and it gave me some directions, I've tried to improve it considering the following things: 1) In case the flowfile has, say, 93 bytes, using Long or UnsignedShort allows only to shift 8 or 4 bytes at the time, making it impossible to read an odd number of bytes. Thus, I've used readUnsignedByte instead. 2) Missing left padding zeros 3) Reading the whole flowfile and dumping it in an attribute, which I've called 'raw' import java.io.DataInputStream
def flowFile = session.get()
if(!flowFile) return
def raw = ''
def aux = ''
boolean eof = false
session.read(flowFile, {inputStream ->
dis = new DataInputStream(inputStream)
while (!eof) {
try {
aux = Integer.toHexString(dis.readUnsignedByte());
raw = raw + aux.padLeft(2,'0');
} catch (EOFException e) {
eof = true;
}
}
} as InputStreamCallback)
flowFile = session.putAttribute(flowFile, 'raw', raw)
session.transfer(flowFile, REL_SUCCESS)
As I am a newbie, please feel free to comment. Cheers, Gus
... View more