Add autoclose

This commit is contained in:
Victor Shcherb 2020-07-21 12:43:21 +02:00
parent 5b3ff4c125
commit cfff07567d
2 changed files with 7 additions and 2 deletions

View file

@ -7,7 +7,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
import java.util.ArrayList;

View file

@ -484,6 +484,10 @@ public class Algorithms {
}
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();
responseBody.setLength(0);
if (i != null) {
@ -498,8 +502,10 @@ public class Algorithms {
}
responseBody.append(s);
}
if (autoclose) {
i.close();
}
}
return responseBody;
}