aboutsummaryrefslogtreecommitdiff
path: root/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java')
-rw-r--r--protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java
index 2a88a3f89..fc578b2c2 100644
--- a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java
+++ b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java
@@ -32,6 +32,7 @@ import io.grpc.Status;
import io.grpc.internal.GrpcUtil;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
@@ -44,6 +45,8 @@ public class ProtoLiteUtils {
private static volatile ExtensionRegistryLite globalRegistry =
ExtensionRegistryLite.getEmptyRegistry();
+ private static final int BUF_SIZE = 8192;
+
/**
* Sets the global registry for proto marshalling shared across all servers and clients.
*
@@ -202,6 +205,24 @@ public class ProtoLiteUtils {
};
}
+ /** Copies the data from input stream to output stream. */
+ static long copy(InputStream from, OutputStream to) throws IOException {
+ // Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta)
+ checkNotNull(from);
+ checkNotNull(to);
+ byte[] buf = new byte[BUF_SIZE];
+ long total = 0;
+ while (true) {
+ int r = from.read(buf);
+ if (r == -1) {
+ break;
+ }
+ to.write(buf, 0, r);
+ total += r;
+ }
+ return total;
+ }
+
private ProtoLiteUtils() {
}
}