diff options
author | Keith Dart <keith.dart@gmail.com> | 2017-09-28 17:54:57 -0700 |
---|---|---|
committer | Ang Li <angli@google.com> | 2017-09-28 17:54:57 -0700 |
commit | 2797e51535fd0906326ba8785159d6d2f96f1e7d (patch) | |
tree | e2a5b29bdd54403b2284b7b406d686956adcb68a /src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java | |
parent | 7f7798eb4b720054f40e0f507c0b2824cabbb405 (diff) | |
download | mobly-bundled-snippets-2797e51535fd0906326ba8785159d6d2f96f1e7d.tar.gz |
Add Rpcs needed to download files via HTTP. (#80)
* Add an Rpc to perform an HTTP download using DownloadManager.
* Add file operation Rpcs.
Diffstat (limited to 'src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java')
-rw-r--r-- | src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java b/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java index c68ae5a..e4c0dbd 100644 --- a/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java +++ b/src/main/java/com/google/android/mobly/snippet/bundled/utils/Utils.java @@ -30,6 +30,8 @@ import java.util.concurrent.TimeoutException; public final class Utils { + private final static char[] hexArray = "0123456789abcdef".toCharArray(); + private Utils() {} /** @@ -190,4 +192,24 @@ public final class Utils { throw e.getCause(); } } + + /** + * Convert a byte array (binary data) to a hexadecimal string (ASCII) + * representation. + + * [\x01\x02] -> "0102" + * + * @param bytes The array of byte to convert. + * @return a String with the ASCII hex representation. + */ + public static String bytesToHexString(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + } |