[hoststubgen] Fix log.iTime()

- iTime() didn't print the log, if the `block` had a return.
  Let's just use a finally to fix it.
  (I din't want to print the log if the code threw, but it's not a big deal.)

- Add vTime() and dTime() while I'm at it.

- Also make copyZipEntry() _slightly_ faster. InputStream.transferTo() still
  uses `write(int)` to write byte-by-byte, but using it makes it a bit fast.
  Although apparently copying entries-by-entires this way is still surprisingly
  slow.

  (HostStubGen doesn't use this method too often, but "ravenizer" will use
  it more often, and that's where I noticed it.)

Test: $ANDROID_BUILD_TOP/frameworks/base/ravenwood/scripts/run-ravenwood-tests.sh
Flag: EXEMPT host side test change only
Bug: 292141694
Change-Id: Id2609d1b44055f92956207ee7f8b4c57e931ce44
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
index 36bfbef..c510eee 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGen.kt
@@ -334,13 +334,14 @@
             entry: ZipEntry,
             out: ZipOutputStream,
             ) {
-        BufferedInputStream(inZip.getInputStream(entry)).use { bis ->
+        // TODO: It seems like copying entries this way is _very_ slow,
+        // even with out.setLevel(0). Look for other ways to do it.
+
+        inZip.getInputStream(entry).use { ins ->
             // Copy unknown entries as is to the impl out. (but not to the stub out.)
             val outEntry = ZipEntry(entry.name)
             out.putNextEntry(outEntry)
-            while (bis.available() > 0) {
-                out.write(bis.read())
-            }
+            ins.transferTo(out)
             out.closeEntry()
         }
     }
diff --git a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
index ee4a06f..fcdf824 100644
--- a/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
+++ b/tools/hoststubgen/hoststubgen/src/com/android/hoststubgen/HostStubGenLogger.kt
@@ -121,7 +121,7 @@
         return level.ordinal <= maxLogLevel.ordinal
     }
 
-    private fun println(level: LogLevel, message: String) {
+    fun println(level: LogLevel, message: String) {
         printers.forEach {
             if (it.logLevel.ordinal >= level.ordinal) {
                 it.println(level, indent, message)
@@ -129,7 +129,7 @@
         }
     }
 
-    private fun println(level: LogLevel, format: String, vararg args: Any?) {
+    fun println(level: LogLevel, format: String, vararg args: Any?) {
         if (isEnabled(level)) {
             println(level, String.format(format, *args))
         }
@@ -185,14 +185,29 @@
         println(LogLevel.Debug, format, *args)
     }
 
-    inline fun <T> iTime(message: String, block: () -> T): T {
+    inline fun <T> logTime(level: LogLevel, message: String, block: () -> T): T {
         val start = System.currentTimeMillis()
-        val ret = block()
-        val end = System.currentTimeMillis()
+        try {
+            return block()
+        } finally {
+            val end = System.currentTimeMillis()
+            if (isEnabled(level)) {
+                println(level,
+                    String.format("%s: took %.1f second(s).", message, (end - start) / 1000.0))
+            }
+        }
+    }
 
-        log.i("%s: took %.1f second(s).", message, (end - start) / 1000.0)
+    inline fun <T> iTime(message: String, block: () -> T): T {
+        return logTime(LogLevel.Info, message, block)
+    }
 
-        return ret
+    inline fun <T> vTime(message: String, block: () -> T): T {
+        return logTime(LogLevel.Verbose, message, block)
+    }
+
+    inline fun <T> dTime(message: String, block: () -> T): T {
+        return logTime(LogLevel.Debug, message, block)
     }
 
     inline fun forVerbose(block: () -> Unit) {