private final State onPayload ( final Buffer buffer ) { if ( contentLength == 0 ) { return State . DONE ; } if ( buffer . getReadableBytes ( ) >= contentLength ) { try { payload = buffer . readBytes ( contentLength ) ; } catch ( final IOException e ) { throw new RuntimeException ( "Unable to read from stream due to IOException" , e ) ; } return State . DONE ; } return State . GET_PAYLOAD ; }
We may or may not have a payload which depends on whether there is a Content - length header available or not . If yes then we will just slice out that entire thing once we have enough readable bytes in the buffer .