private static State next(final InputStream stream,final State state,final ByteArrayOutputStream line) throws IOException {
  final int next=stream.read();
  if (next == -1) {
    throw new IOException("chunked stream ended unexpectedly");
  }
  final State result;
switch (state) {
case NORMAL:
    result=nextNormal(state,line,next);
  break;
case R:
if (next == '\n') {
  result=State.END;
}
 else {
  throw new IOException(String.format("%s%s","Protocol violation: Unexpected"," single newline character in chunk size"));
}
break;
case QUOTED_STRING:
result=nextQuoted(stream,state,line,next);
break;
default :
throw new IllegalStateException("Bad state");
}
return result;
}

private static State next ( final InputStream stream , final State state , final ByteArrayOutputStream line ) throws IOException { final int next = stream . read ( ) ; if ( next == - 1 ) { throw new IOException ( "chunked stream ended unexpectedly" ) ; } final State result ; switch ( state ) { case NORMAL : result = nextNormal ( state , line , next ) ; break ; case R : if ( next == '\n' ) { result = State . END ; } else { throw new IOException ( String . format ( "%s%s" , "Protocol violation: Unexpected" , " single newline character in chunk size" ) ) ; } break ; case QUOTED_STRING : result = nextQuoted ( stream , state , line , next ) ; break ; default : throw new IllegalStateException ( "Bad state" ) ; } return result ; }
get next state for fsm .
