Reduce dependency on commons-io and commons-codec (#10614)
Signed-off-by: Wouter Born <github@maindrain.net>
This commit is contained in:
@@ -16,7 +16,9 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
@@ -25,7 +27,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.openhab.binding.ihc.internal.ws.datatypes.WSControllerState;
|
||||
import org.openhab.binding.ihc.internal.ws.datatypes.WSFile;
|
||||
import org.openhab.binding.ihc.internal.ws.datatypes.WSLoginResult;
|
||||
@@ -325,10 +326,13 @@ public class IhcClient {
|
||||
}
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(byteStream.toString());
|
||||
logger.debug("File size after base64 encoding: {} bytes", decodedBytes.length);
|
||||
try (GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes))) {
|
||||
try (InputStreamReader in = new InputStreamReader(gzis, "ISO-8859-1")) {
|
||||
return IOUtils.toByteArray(in, "ISO-8859-1");
|
||||
}
|
||||
try (GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
|
||||
InputStreamReader reader = new InputStreamReader(gzis, StandardCharsets.ISO_8859_1);
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
OutputStreamWriter writer = new OutputStreamWriter(baos)) {
|
||||
reader.transferTo(writer);
|
||||
writer.flush();
|
||||
return baos.toByteArray();
|
||||
}
|
||||
}
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
|
||||
@@ -14,6 +14,7 @@ package org.openhab.binding.ihc.internal.ws.projectfile;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -24,7 +25,6 @@ import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.openhab.binding.ihc.internal.ws.datatypes.WSProjectInfo;
|
||||
import org.openhab.binding.ihc.internal.ws.exeptions.IhcExecption;
|
||||
import org.slf4j.Logger;
|
||||
@@ -76,7 +76,10 @@ public class ProjectFileUtils {
|
||||
*/
|
||||
public static void saveToFile(String filePath, byte[] data) throws IhcExecption {
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(new File(filePath), data);
|
||||
try (FileOutputStream stream = new FileOutputStream(filePath)) {
|
||||
stream.write(data);
|
||||
stream.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IhcExecption(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user