mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
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:
parent
aa3f73d423
commit
1bc55a208b
@ -32,7 +32,6 @@ import java.time.zone.ZoneRules;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openhab.binding.airvisualnode.internal.config.AirVisualNodeConfig;
|
||||
import org.openhab.binding.airvisualnode.internal.json.NodeData;
|
||||
import org.openhab.core.library.types.DateTimeType;
|
||||
@ -178,7 +177,7 @@ public class AirVisualNodeHandler extends BaseThingHandler {
|
||||
String url = "smb://" + nodeAddress + "/" + nodeShareName + "/" + NODE_JSON_FILE;
|
||||
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, nodeUsername, nodePassword);
|
||||
try (SmbFileInputStream in = new SmbFileInputStream(new SmbFile(url, auth))) {
|
||||
return IOUtils.toString(in, StandardCharsets.UTF_8.name());
|
||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -89,7 +88,7 @@ public class DeconzTest {
|
||||
}
|
||||
|
||||
public static <T> T getObjectFromJson(String filename, Class<T> clazz, Gson gson) throws IOException {
|
||||
String json = IOUtils.toString(DeconzTest.class.getResourceAsStream(filename), StandardCharsets.UTF_8.name());
|
||||
String json = new String(DeconzTest.class.getResourceAsStream(filename).readAllBytes(), StandardCharsets.UTF_8);
|
||||
return gson.fromJson(json, clazz);
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -16,9 +16,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.openhab.binding.foobot.internal.FoobotApiConnector;
|
||||
@ -38,7 +38,7 @@ public class FoobotAccountHandlerTest {
|
||||
@Override
|
||||
protected String request(String url, String apiKey) throws FoobotApiException {
|
||||
try (InputStream stream = getClass().getResourceAsStream("../devices.json")) {
|
||||
return IOUtils.toString(stream);
|
||||
return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e.getMessage());
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.openhab.binding.foobot.internal.FoobotApiConnector;
|
||||
@ -40,7 +40,7 @@ public class FoobotDeviceHandlerTest {
|
||||
@Override
|
||||
protected String request(String url, String apiKey) throws FoobotApiException {
|
||||
try (InputStream stream = getClass().getResourceAsStream("../sensors.json")) {
|
||||
return IOUtils.toString(stream);
|
||||
return new String(stream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new AssertionError(e.getMessage());
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ package org.openhab.binding.fsinternetradio.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@ -24,7 +25,6 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.openhab.binding.fsinternetradio.internal.radio.FrontierSiliconRadioConstants;
|
||||
|
||||
@ -238,11 +238,11 @@ public class RadioServiceDummy extends HttpServlet {
|
||||
}
|
||||
|
||||
private String makeValidXMLResponse() throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream("/validXml.xml"));
|
||||
return new String(getClass().getResourceAsStream("/validXml.xml").readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String makeInvalidXMLResponse() throws IOException {
|
||||
return IOUtils.toString(getClass().getResourceAsStream("/invalidXml.xml"));
|
||||
return new String(getClass().getResourceAsStream("/invalidXml.xml").readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public void setInvalidResponse(boolean value) {
|
||||
|
@ -18,8 +18,8 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -80,13 +80,15 @@ public class MillHeatAccountHandlerTest {
|
||||
|
||||
@Test
|
||||
public void testUpdateModel() throws InterruptedException, IOException, MillheatCommunicationException {
|
||||
final String getHomesResponse = IOUtils.toString(getClass().getResourceAsStream("/select_home_list_ok.json"));
|
||||
final String getRoomsByHomeResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_rooms_by_home_ok.json"));
|
||||
final String getDeviceByRoomResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_device_by_room_ok.json"));
|
||||
final String getIndependentDevicesResponse = IOUtils
|
||||
.toString(getClass().getResourceAsStream("/get_independent_devices_ok.json"));
|
||||
final String getHomesResponse = new String(
|
||||
getClass().getResourceAsStream("/select_home_list_ok.json").readAllBytes(), StandardCharsets.UTF_8);
|
||||
final String getRoomsByHomeResponse = new String(
|
||||
getClass().getResourceAsStream("/get_rooms_by_home_ok.json").readAllBytes(), StandardCharsets.UTF_8);
|
||||
final String getDeviceByRoomResponse = new String(
|
||||
getClass().getResourceAsStream("/get_device_by_room_ok.json").readAllBytes(), StandardCharsets.UTF_8);
|
||||
final String getIndependentDevicesResponse = new String(
|
||||
getClass().getResourceAsStream("/get_independent_devices_ok.json").readAllBytes(),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
stubFor(post(urlEqualTo("/millService/v1/selectHomeList"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getHomesResponse)));
|
||||
|
@ -16,9 +16,9 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openhab.binding.sensibo.internal.dto.AbstractRequest;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@ -51,7 +51,8 @@ public class WireHelper {
|
||||
}
|
||||
|
||||
public <T> T deSerializeResponse(final String jsonClasspathName, final Type type) throws IOException {
|
||||
final String json = IOUtils.toString(WireHelper.class.getResourceAsStream(jsonClasspathName));
|
||||
final String json = new String(WireHelper.class.getResourceAsStream(jsonClasspathName).readAllBytes(),
|
||||
StandardCharsets.UTF_8);
|
||||
|
||||
final JsonParser parser = new JsonParser();
|
||||
final JsonObject o = parser.parse(json).getAsJsonObject();
|
||||
@ -61,7 +62,8 @@ public class WireHelper {
|
||||
}
|
||||
|
||||
public <T> T deSerializeFromClasspathResource(final String jsonClasspathName, final Type type) throws IOException {
|
||||
final String json = IOUtils.toString(WireHelper.class.getResourceAsStream(jsonClasspathName));
|
||||
final String json = new String(WireHelper.class.getResourceAsStream(jsonClasspathName).readAllBytes(),
|
||||
StandardCharsets.UTF_8);
|
||||
return deSerializeFromString(json, type);
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,9 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -87,12 +87,14 @@ public class SensiboAccountHandlerTest {
|
||||
when(configuration.as(eq(SensiboAccountConfiguration.class))).thenReturn(accountConfig);
|
||||
|
||||
// Setup initial response
|
||||
final String getPodsResponse = IOUtils.toString(getClass().getResourceAsStream(podsResponse));
|
||||
final String getPodsResponse = new String(getClass().getResourceAsStream(podsResponse).readAllBytes(),
|
||||
StandardCharsets.UTF_8);
|
||||
stubFor(get(urlEqualTo("/api/v2/users/me/pods?apiKey=APIKEY"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getPodsResponse)));
|
||||
|
||||
// Setup 2nd response with details
|
||||
final String getPodDetailsResponse = IOUtils.toString(getClass().getResourceAsStream(podDetailsResponse));
|
||||
final String getPodDetailsResponse = new String(
|
||||
getClass().getResourceAsStream(podDetailsResponse).readAllBytes(), StandardCharsets.UTF_8);
|
||||
stubFor(get(urlEqualTo("/api/v2/pods/PODID?apiKey=APIKEY&fields=*"))
|
||||
.willReturn(aResponse().withStatus(200).withBody(getPodDetailsResponse)));
|
||||
|
||||
|
@ -18,6 +18,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
@ -27,7 +28,6 @@ import java.util.Optional;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.spotify.internal.api.exception.SpotifyException;
|
||||
@ -107,7 +107,7 @@ public class SpotifyAuthService {
|
||||
String.format("Cannot find '{}' - failed to initialize Spotify servlet", templateName));
|
||||
} else {
|
||||
try (InputStream inputStream = index.openStream()) {
|
||||
return IOUtils.toString(inputStream);
|
||||
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ package org.openhab.binding.tplinksmarthome.internal.model;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
@ -58,8 +57,7 @@ public final class ModelTestUtil {
|
||||
* @throws IOException when file could not be read.
|
||||
*/
|
||||
public static String readJson(String filename) throws IOException {
|
||||
return IOUtils
|
||||
.toString(ModelTestUtil.class.getResourceAsStream(filename + ".json"), StandardCharsets.UTF_8.name())
|
||||
.replaceAll("[\n\r\t ]", "");
|
||||
return new String(ModelTestUtil.class.getResourceAsStream(filename + ".json").readAllBytes(),
|
||||
StandardCharsets.UTF_8).replaceAll("[\n\r\t ]", "");
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ package org.openhab.binding.yamahareceiver.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Helper for loading XML files from classpath.
|
||||
@ -29,7 +28,7 @@ public class ResponseLoader {
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
return IOUtils.toString(in);
|
||||
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,13 +19,13 @@ import static org.openhab.core.thing.ThingStatus.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -138,7 +138,8 @@ public class FeedHandlerTest extends JavaOSGiTest {
|
||||
|
||||
public void setFeedContent(String feedContentFile) throws IOException {
|
||||
String path = "input/" + feedContentFile;
|
||||
feedContent = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream(path));
|
||||
feedContent = new String(getClass().getClassLoader().getResourceAsStream(path).readAllBytes(),
|
||||
StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user