public static AsyncWork < XMLStreamReader , Exception > start ( IO . Readable . Buffered io , int charactersBufferSize , int maxBuffers ) { AsyncWork < XMLStreamReader , Exception > result = new AsyncWork <> ( ) ; new Task . Cpu . FromRunnable ( "Start reading XML " + io . getSourceDescription ( ) , io . getPriority ( ) , ( ) -> { XMLStreamReader reader = new XMLStreamReader ( io , charactersBufferSize , maxBuffers ) ; try { Starter start = new Starter ( io , reader . defaultEncoding , reader . charactersBuffersSize , reader . maxBuffers ) ; reader . stream = start . start ( ) ; reader . stream . canStartReading ( ) . listenAsync ( new Task . Cpu . FromRunnable ( "Start reading XML " + io . getSourceDescription ( ) , io . getPriority ( ) , ( ) -> { try { reader . next ( ) ; result . unblockSuccess ( reader ) ; } catch ( Exception e ) { result . unblockError ( e ) ; } } ) , true ) ; } catch ( Exception e ) { result . unblockError ( e ) ; } } ) . startOn ( io . canStartReading ( ) , true ) ; return result ; }
Utility method that initialize a XMLStreamReader initialize it and return an AsyncWork which is unblocked when characters are available to be read .