WestRidgeSystems / jmisb

jMISB is an open source Java library implementing various MISB standards.
MIT License
41 stars 12 forks source link

Add parseStream(InputStream) to KlvParser #443

Closed ruckc closed 1 year ago

ruckc commented 1 year ago

Motivation and Context

442 - reference issue. This is just a WIP attempt to provide InputStream parsing in KlvParser.

Description

Added the below method to KlvParser.

    public static void parseStream(
            InputStream is,
            Consumer<IMisbMessage> handler,
            Consumer<KlvParseException> exceptionHandler)

Given that parseBytes() throws a KlvParseException on bad data, and when dealing with a stream, you may want the ability to continue processing, this required the ability to emit IMisbMessage and/or KlvParseExceptions without breaking the stream.

How Has This Been Tested?

I tested with a mock application I'm developing where ffmpeg is running externally and its outputting the KLV data stream to stdout, which is being processed by KlvParser.

Types of changes

Checklist:

ruckc commented 1 year ago

Just realized I based this on main/1.x branch. Updating 2.x now.

bradh commented 1 year ago

Looks like a worthwhile change. The only thought I had (without a proper review) is to check that the BER and BER-OID lengths aren't excessive. If you are trying to deal with potentially corrupted data, then that can cause reading of a really large amount of data from the stream.

Also (for the general case), when things go wrong, the exception doesn't have to go uncaught, and you can log and continue.