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