fix: 修掉命令输出读取的并发访问与缓存流重复关闭
- CmdUtil.StreamCollector 追加内容时与读取方同步,避免 StringBuilder 并发读写 - CacheHelper.getAsString 只在未创建 reader 时单独关闭输入流
This commit is contained in:
1 parent
b80e9f9082
commit
513447ec7a
2 files changed
+8
-7
No files matched your search
@@ -210,14 +210,13 @@ public class CacheHelper {
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "getAsString: " + e.getMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (isr != null) {
|
||||
if (isr != null) {
|
||||
try {
|
||||
isr.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "getAsString: " + e.getMessage(), e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "getAsString: " + e.getMessage(), e);
|
||||
}
|
||||
if (inputStream != null) {
|
||||
} else if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -109,7 +109,9 @@ public class CmdUtil {
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
content.append(line);
|
||||
synchronized (content) {
|
||||
content.append(line);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "StreamCollector.run: " + e.getMessage(), e);
|
||||
|
||||
Reference in new issue
Block a user