question: public byte [ ] receiveMessage ( ) throws IOException { byte [ ] prefix = new byte [ 4 ] ; int idx = 0 ; while ( idx < 4 ) { int read = in . read ( prefix , idx , 4 - idx ) ; if ( read < 0 ) throw new IOException ( "End of stream reached before message length was read." ) ; idx += read ; } int len = U . bytesToInt ( prefix , 0 ) ; byte [ ] res = new byte [ len ] ; idx = 0 ; while ( idx < len ) { int read = in . read ( res , idx , len - idx ) ; if ( read < 0 ) throw new IOException ( "End of stream reached before message body was read." ) ; idx += read ; } return res ; }
target:  Reads prefixed bytes from socket input stream. Note that this method may block forever if there is not enough bytes available in socket input stream.