public int decodeElements ( TypedArrayDecoder tad , InputProblemReporter rep ) throws TypedXMLStreamException { int count = 0 ; /* First: for simplicity, we require a single flat buffer to * decode from. Second: to be able to update start location * (to keep track of what's available), we need to fake that * we are using a shared buffer (since that has offset) */ if ( mInputStart < 0 ) { if ( mHasSegments ) { mInputBuffer = buildResultArray ( ) ; mInputLen = mInputBuffer . length ; // let's also clear segments since they are not needed any more clearSegments ( ) ; } else { // just current buffer, easier to fake mInputBuffer = mCurrentSegment ; mInputLen = mCurrentSize ; } mInputStart = 0 ; } // And then let's decode int ptr = mInputStart ; final int end = ptr + mInputLen ; final char [ ] buf = mInputBuffer ; int start = ptr ; try { decode_loop : while ( ptr < end ) { // First, any space to skip? while ( buf [ ptr ] <= INT_SPACE ) { if ( ++ ptr >= end ) { break decode_loop ; } } // Then let's figure out non-space char (token) start = ptr ; ++ ptr ; while ( ptr < end && buf [ ptr ] > INT_SPACE ) { ++ ptr ; } ++ count ; int tokenEnd = ptr ; ++ ptr ; // to skip trailing space (or, beyond end) // And there we have it if ( tad . decodeValue ( buf , start , tokenEnd ) ) { break ; } } } catch ( IllegalArgumentException iae ) { // Need to convert to a checked stream exception /* Hmmh. This is probably not an accurate location... but * we can't do much better as content we have has been * normalized already. */ Location loc = rep . getLocation ( ) ; // -1 to move it back after being advanced earlier (to skip trailing space) String lexical = new String ( buf , start , ( ptr - start - 1 ) ) ; throw new TypedXMLStreamException ( lexical , iae . getMessage ( ) , loc , iae ) ; } finally { mInputStart = ptr ; mInputLen = end - ptr ; } return count ; }
Pass - through decode method called to find find the next token decode it and repeat the process as long as there are more tokens and the array decoder accepts more entries . All tokens processed will be consumed such that they will not be visible via buffer .