I\'m new to Java, so I would like to use the standard solution for, I think, the standard task. The length of tags and values are not known.
Might be this free library can be useful for you. I've used this one for simple TLV parsing. Anyway it's with MIT license and you can modify it.
https://github.com/VakhoQ/tlv-encoder