code: 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;
      }
docs: Get next state for FSM.
  @param stream Input stream.
  @param state Current state.
  @param line Current chunk size line.
  @return New state.
  @throws IOException If fails.