AAPT2: Better debugging output

Test: make aapt2_tests
Change-Id: I7778b773201381538dc1f2e376abee4eb33e44c0
diff --git a/tools/aapt2/io/Util.cpp b/tools/aapt2/io/Util.cpp
index d270340..7ee1016 100644
--- a/tools/aapt2/io/Util.cpp
+++ b/tools/aapt2/io/Util.cpp
@@ -18,6 +18,7 @@
 
 #include "google/protobuf/io/zero_copy_stream_impl_lite.h"
 
+using ::android::StringPiece;
 using ::google::protobuf::io::ZeroCopyOutputStream;
 
 namespace aapt {
@@ -93,6 +94,25 @@
   return !in->HadError();
 }
 
+bool Copy(OutputStream* out, const StringPiece& in) {
+  const char* in_buffer = in.data();
+  size_t in_len = in.size();
+  while (in_len != 0) {
+    void* out_buffer;
+    size_t out_len;
+    if (!out->Next(&out_buffer, &out_len)) {
+      return false;
+    }
+
+    const size_t bytes_to_copy = in_len < out_len ? in_len : out_len;
+    memcpy(out_buffer, in_buffer, bytes_to_copy);
+    out->BackUp(out_len - bytes_to_copy);
+    in_buffer += bytes_to_copy;
+    in_len -= bytes_to_copy;
+  }
+  return true;
+}
+
 bool Copy(ZeroCopyOutputStream* out, InputStream* in) {
   OutputStreamAdaptor adaptor(out);
   return Copy(&adaptor, in);