aboutsummaryrefslogtreecommitdiff
path: root/protobuf-lite
diff options
context:
space:
mode:
authorzpencer <spencerfang@google.com>2017-09-14 19:39:06 -0700
committerGitHub <noreply@github.com>2017-09-14 19:39:06 -0700
commit2b1363d58600ac49b73116e00d17302063ef532a (patch)
treecf1a4358d4e09a08f0f9df42bb24fb2edaee31b6 /protobuf-lite
parentbb203657cb70e1361722a928c03a70630aea0757 (diff)
downloadgrpc-grpc-java-2b1363d58600ac49b73116e00d17302063ef532a.tar.gz
core,netty,okhttp,protobuf-lite: avoid @Beta guava classes (#3463)
Diffstat (limited to 'protobuf-lite')
-rw-r--r--protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoInputStream.java3
-rw-r--r--protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoLiteUtils.java21
2 files changed, 22 insertions, 2 deletions
diff --git a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoInputStream.java b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoInputStream.java
index 47263bbbc..e5743627e 100644
--- a/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoInputStream.java
+++ b/protobuf-lite/src/main/java/io/grpc/protobuf/lite/ProtoInputStream.java
@@ -16,7 +16,6 @@
package io.grpc.protobuf.lite;
-import com.google.common.io.ByteStreams;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.MessageLite;
import com.google.protobuf.Parser;
@@ -53,7 +52,7 @@ class ProtoInputStream extends InputStream implements Drainable, KnownLength {
message.writeTo(target);
message = null;
} else if (partial != null) {
- written = (int) ByteStreams.copy(partial, target);
+ written = (int) ProtoLiteUtils.copy(partial, target);
partial = null;
} else {
written = 0;
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() {
}
}