Add autoclose
This commit is contained in:
parent
5b3ff4c125
commit
cfff07567d
2 changed files with 7 additions and 2 deletions
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -484,6 +484,10 @@ public class Algorithms {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StringBuilder readFromInputStream(InputStream i) throws IOException {
|
public static StringBuilder readFromInputStream(InputStream i) throws IOException {
|
||||||
|
return readFromInputStream(i, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static StringBuilder readFromInputStream(InputStream i, boolean autoclose) throws IOException {
|
||||||
StringBuilder responseBody = new StringBuilder();
|
StringBuilder responseBody = new StringBuilder();
|
||||||
responseBody.setLength(0);
|
responseBody.setLength(0);
|
||||||
if (i != null) {
|
if (i != null) {
|
||||||
|
@ -498,7 +502,9 @@ public class Algorithms {
|
||||||
}
|
}
|
||||||
responseBody.append(s);
|
responseBody.append(s);
|
||||||
}
|
}
|
||||||
i.close();
|
if (autoclose) {
|
||||||
|
i.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return responseBody;
|
return responseBody;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue