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.
This commit is contained in:
Peter Cai 2022-07-09 21:07:58 -04:00
parent 4a78393636
commit 83f593a703
3 changed files with 12 additions and 3 deletions

View File

@ -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'

View File

@ -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;
}

View File

@ -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()
}