Skip to content

Commit

Permalink
修复Test中System.in.read()导致的内存溢出
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Feb 2, 2023
1 parent 829bc4e commit bbcc9c1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,11 @@ static public String ReadIn() throws Exception {
if(byt=='\n') {
break;
}
if(in.size()>=2048) {//防止内存溢出,某些环境下可能会有无限的输入
byte[] bytes=in.toByteArray();
in=new ByteArrayOutputStream();
in.write(bytes, bytes.length-1024, 1024);
}
in.write(byt);
}
return in.toString();
Expand Down

0 comments on commit bbcc9c1

Please sign in to comment.