@@ -944,7 +944,7 @@ private void send(int opcode, byte[] payload) throws IOException {
944944 */
945945 private void read () throws IOException {
946946 // If message contains fragmented parts we should put it all together.
947- LinkedList <byte []> messageParts = new LinkedList <byte [] >();
947+ LinkedList <byte []> messageParts = new LinkedList <>();
948948
949949 // The first byte of every data frame
950950 int firstByte ;
@@ -980,7 +980,10 @@ private void read() throws IOException {
980980 if (payloadLength == 126 ) {
981981 // Attempts to read the next 2 bytes
982982 byte [] nextTwoBytes = new byte [2 ];
983- if (bis .read (nextTwoBytes ) == -1 ) break ;
983+ for (int i = 0 ; i < 2 ; i ++) {
984+ byte b = (byte ) bis .read ();
985+ nextTwoBytes [i ] = b ;
986+ }
984987
985988 // Those last 2 bytes will be interpreted as a 16-bit
986989 // unsigned
@@ -990,7 +993,10 @@ private void read() throws IOException {
990993 } else if (payloadLength == 127 ) {
991994 // Attempts to read the next 8 bytes
992995 byte [] nextEightBytes = new byte [8 ];
993- if (bis .read (nextEightBytes ) == -1 ) break ;
996+ for (int i = 0 ; i < 8 ; i ++) {
997+ byte b = (byte ) bis .read ();
998+ nextEightBytes [i ] = b ;
999+ }
9941000
9951001 // Only the last 4 bytes matter because Java doesn't support
9961002 // arrays with more than 2^31 -1 elements, so a 64-bit
@@ -1006,7 +1012,10 @@ private void read() throws IOException {
10061012
10071013 // Attempts to read the payload data
10081014 byte [] data = new byte [payloadLength ];
1009- if (bis .read (data ) == -1 ) break ;
1015+ for (int i = 0 ; i < payloadLength ; i ++) {
1016+ byte b = (byte ) bis .read ();
1017+ data [i ] = b ;
1018+ }
10101019
10111020 if (isLast ) {
10121021 // If we already have some fragments, just add last and put it together
0 commit comments