question: protected PostgresMessages readMessage ( boolean hasType ) throws IOException { PostgresMessages type ; int code = - 1 ; if ( hasType ) { try { beforeIdle ( ) ; while ( true ) { try { code = dataInput . read ( ) ; } catch ( SocketTimeoutException ex ) { idle ( ) ; continue ; } if ( ! PostgresMessages . readTypeCorrect ( code ) ) { throw new IOException ( "Bad protocol read message: " + ( char ) code ) ; } type = PostgresMessages . messageType ( code ) ; break ; } } finally { afterIdle ( ) ; } } else { type = PostgresMessages . STARTUP_MESSAGE_TYPE ; code = 0 ; } if ( code < 0 ) return PostgresMessages . EOF_TYPE ; recvTap . in ( ) ; try { int count = 0 ; if ( code > 0 ) count ++ ; int len = dataInput . readInt ( ) ; if ( ( len < 0 ) || ( len > type . maxSize ( ) ) ) throw new IOException ( String . format ( "Implausible message length (%d) received." , len ) ) ; count += len ; len -= 4 ; try { rawMessageInput = new byte [ len ] ; dataInput . readFully ( rawMessageInput , 0 , len ) ; messageInput = new DataInputStream ( new ByteArrayInputStream ( rawMessageInput ) ) ; } catch ( OutOfMemoryError ex ) { throw new IOException ( String . format ( "Unable to allocate read buffer of length (%d)" , len ) ) ; } bytesRead ( count ) ; return type ; } finally { recvTap . out ( ) ; } }
target:  Read the next message from the stream, starting with the message type opcode. 