次の Java コード スニペットでは、次の行が表示されます。packetLengthMax += bytes.toByteArray()[43];
私の質問は次のとおりです。
byte[] dataBuffer = new byte[265];
int packetLength = 0;
int packetLengthMax = 44;
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream outMessage = new DataOutputStream(bytes);
/* Client = Socket*/
DataInputStream clientIn = new DataInputStream(Client.getInputStream());
while (packetLength < packetLengthMax) {
packetLength += clientIn.read(dataBuffer);
outMessage.write(dataBuffer);
if (packetLength >= 43) {
packetLengthMax += bytes.toByteArray()[43];
}
}
私の説明: まず、ソケット ( Client
) がコードに渡されます。次に、すべての変数のセットアップを行います。while ループでは、ソケットからのすべてのデータを読み取ります。次に、このデータも に書き込みますDataOutputStream
。しかし、if
ステートメントでは、バイト配列を整数に追加します。
それはどのように機能しますか?その点がわかりません。助けてくれてありがとう!