From 70331f6f3c319a17db7f5e14d33ed38d1e5e9662 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Thu, 29 Oct 2020 11:40:18 +0100 Subject: [PATCH] Finished reading from stream --- src/main/java/Main/ProtocolMessage.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/Main/ProtocolMessage.java b/src/main/java/Main/ProtocolMessage.java index 47c68d1..2764e30 100644 --- a/src/main/java/Main/ProtocolMessage.java +++ b/src/main/java/Main/ProtocolMessage.java @@ -114,6 +114,17 @@ public class ProtocolMessage { totalBytesRead += bytesRead; } + int messageLength = charArrayToInt(this.raw); + while(totalBytesRead != 4 + messageLength){ + int bytesRead = reader.read(this.raw, totalBytesRead, messageLength - totalBytesRead); + if (bytesRead == -1) { + logger.log(Level.ERROR, "Invalid packet."); + return; + } else + totalBytesRead += bytesRead; + } + + deconstructPacket(this.raw); }