Specifically the toString reading from inputstream.
Signed-off-by: Hilbrand Bouwkamp <hilbrand@h72.nl>
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;
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);
}
}
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;
}
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);
}
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;
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")) {
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;
}
}
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) {
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;
@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());
}
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;
@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());
}
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;
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;
}
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) {
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;
@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)));
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;
}
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();
}
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);
}
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;
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)));
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;
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;
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);
}
}
}
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;
* @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 ]", "");
}
}
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.
if (in == null) {
return null;
}
- return IOUtils.toString(in);
+ return new String(in.readAllBytes(), StandardCharsets.UTF_8);
}
}
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;
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);
}
}