Removed usage to IOUtils.toString (#8579)

Specifically the toString reading from inputstream.

Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
This commit is contained in:
Hilbrand Bouwkamp
2020-09-25 20:46:14 +02:00
committed by GitHub
parent aa3f73d423
commit 1bc55a208b
13 changed files with 46 additions and 43 deletions

View File

@@ -22,6 +22,7 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -257,9 +258,9 @@ public class HttpTransportImpl implements HttpTransport {
final int responseCode = connection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_FORBIDDEN) {
if (responseCode == HttpURLConnection.HTTP_INTERNAL_ERROR) {
response = IOUtils.toString(connection.getErrorStream());
response = new String(connection.getErrorStream().readAllBytes(), StandardCharsets.UTF_8);
} else {
response = IOUtils.toString(connection.getInputStream());
response = new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
}
if (response != null) {
if (!response.contains("Authentication failed")) {
@@ -380,7 +381,8 @@ public class HttpTransportImpl implements HttpTransport {
if (connection != null) {
connection.connect();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
if (IOUtils.toString(connection.getInputStream()).contains("Authentication failed")) {
if (new String(connection.getInputStream().readAllBytes(), StandardCharsets.UTF_8)
.contains("Authentication failed")) {
return ConnectionManager.AUTHENTIFICATION_PROBLEM;
}
}
@@ -419,13 +421,12 @@ public class HttpTransportImpl implements HttpTransport {
File dssCert = new File(path);
if (dssCert.exists()) {
if (path.endsWith(".crt")) {
try {
InputStream certInputStream = new FileInputStream(dssCert);
String cert = IOUtils.toString(certInputStream);
try (InputStream certInputStream = new FileInputStream(dssCert)) {
String cert = new String(certInputStream.readAllBytes(), StandardCharsets.UTF_8);
if (cert.startsWith(BEGIN_CERT)) {
return cert;
} else {
logger.error("File is not a PEM certificate file. PEM-Certificats starts with: {}",
logger.error("File is not a PEM certificate file. PEM-Certificates starts with: {}",
BEGIN_CERT);
}
} catch (FileNotFoundException e) {