private void readIncomingMessage() {
try {
StringBuilder builder = new StringBuilder();
InputStream is = socket.getInputStream();
int length = 1024;
byte[] array = new byte[length];
int n = 0;
while ((n = is.read(array, n, 100)) != -1) {
builder.append(new String(array));
if (checkIfComplete(builder.toString())) {
buildListItems(builder.toString(), null);
builder = new StringBuilder();
}
}
} catch (IOException e) {
Log.e("TCPclient", "Something went wrong while reading the socket");
}
}
やあ、
100バイトのブロックごとにストリームを読み取り、それらのバイトを文字列に変換して、その文字列が特定の条件に適合するかどうかを確認したいと思います。
しかし、デバッグすると、ビルダーのカウントが3072であることがわかり
ます
。また、(text 、、、、、、、、、、、、、 text 、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
文字列ビルダーへのテキスト?
どうも :)
private void readIncomingMessage() {
try {
StringBuilder builder = new StringBuilder();
InputStream is = socket.getInputStream();
int length = 100;
byte[] array = new byte[length];
int n = 0;
while ((n = is.read(array, 0, length)) != -1) {
builder.append(new String(array, 0, n));
if (checkIfComplete(builder.toString())) {
buildListItems(builder.toString(), null);
builder = new StringBuilder();
}
}
} catch (IOException e) {
Log.e("TCPclient", "Something went wrong while reading the socket");
}
}
この解決策は私のためにトリックをしました。このソリューションの欠点はありますか?