public static Buffer expectDigit ( final Buffer buffer ) throws SipParseException { final int start = buffer . getReaderIndex ( ) ; try { while ( buffer . hasReadableBytes ( ) && isNextDigit ( buffer ) ) { // consume it buffer . readByte ( ) ; } if ( start == buffer . getReaderIndex ( ) ) { throw new SipParseException ( start , "Expected digit" ) ; } return buffer . slice ( start , buffer . getReaderIndex ( ) ) ; } catch ( final IndexOutOfBoundsException e ) { throw new SipParseException ( start , "Expected digit but no more bytes to read" ) ; } catch ( final IOException e ) { throw new SipParseException ( start , "Expected digit unable to read from underlying stream" ) ; } }
Will expect at least 1 digit and will continue consuming bytes until a non - digit is encountered