class JfrEventParser implements JsonEventAdapter {

    @Override
    public CommonEvent parseNextEvent(JsonEventSource source) throws IOException {
        nextEvent = null;
        while(true) {
            streamHandler.reset(handlerProxy);
            if (!source.readNext(streamHandler)) {
                return null;
            }
            if (!streamHandler.isAcomplished()) {
                throw new IOException("Malformed JSON input");
            }
            if (nextEvent != null) {
                return nextEvent;
            }
        }
    }

}