瀏覽代碼

Remove dependence on commons-io

We would like to reduce dependency on Apache commons as much as
possible. Although we probably won't be able to build this in AOSP
anyway, it is still good to move away when we have better alternatives
in the Kotlin runtime.
Peter Cai 3 年之前
父節點
當前提交
83f593a703

+ 0 - 1
libs/lpad-sm-dp-plus-connector/build.gradle

@@ -11,7 +11,6 @@ dependencies {
     implementation 'com.beanit:asn1bean:1.13.0'
     implementation 'com.fazecast:jSerialComm:1.3.11'
     implementation 'org.apache.commons:commons-lang3:3.7'
-    implementation 'commons-io:commons-io:2.6'
     implementation 'commons-codec:commons-codec:1.11'
     implementation 'com.google.code.gson:gson:2.8.4'
     testImplementation 'junit:junit:4.12'

+ 3 - 2
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/es9plus/HttpRSPClient.java

@@ -1,7 +1,8 @@
 package com.truphone.es9plus;
 
 import com.truphone.util.LogStub;
-import org.apache.commons.io.IOUtils;
+import com.truphone.util.TextUtil;
+
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.BufferedWriter;
@@ -89,7 +90,7 @@ public class HttpRSPClient {
         os.close();
 
         httpResponse.setStatusCode(con.getResponseCode());
-        httpResponse.setContent(IOUtils.toString(con.getInputStream(), StandardCharsets.UTF_8));
+        httpResponse.setContent(new String(TextUtil.readInputStream(con.getInputStream()), StandardCharsets.UTF_8));
 
         return httpResponse;
     }

+ 9 - 0
libs/lpad-sm-dp-plus-connector/src/main/java/com/truphone/util/TextUtil.kt

@@ -1,5 +1,6 @@
 package com.truphone.util
 
+import java.io.InputStream
 import java.lang.StringBuilder
 
 object TextUtil {
@@ -77,4 +78,12 @@ object TextUtil {
         }
         return builder.toString()
     }
+
+    /*
+     * Read an InputStream into a ByteArray
+     * This is exposed to the Java side as a convenience
+     * TODO: Remove when we migrate the full code base to Kotlin
+     */
+    @JvmStatic
+    fun readInputStream(i: InputStream): ByteArray = i.readBytes()
 }