aboutsummaryrefslogtreecommitdiff
path: root/protobuf-nano
diff options
context:
space:
mode:
authorzpencer <spencerfang@google.com>2017-09-06 07:30:58 -0700
committerGitHub <noreply@github.com>2017-09-06 07:30:58 -0700
commit671783f912539b41450117a6c81e1009fde5471d (patch)
treeb1b1084320ddec09e088e607389be18b6d01e310 /protobuf-nano
parent78831690f689d3f4baefaa3b8b04f6a7f20fad4b (diff)
downloadgrpc-grpc-java-671783f912539b41450117a6c81e1009fde5471d.tar.gz
protobuf-nano: use existing class IoUtils for toByteArray (#3437)
protobuf-nano: use existing class IoUtils and force protobuf-nano to use exact version of internal
Diffstat (limited to 'protobuf-nano')
-rw-r--r--protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java30
1 files changed, 2 insertions, 28 deletions
diff --git a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java
index a1c10a6c7..35648c9d6 100644
--- a/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java
+++ b/protobuf-nano/src/main/java/io/grpc/protobuf/nano/NanoUtils.java
@@ -16,16 +16,14 @@
package io.grpc.protobuf.nano;
-import static com.google.common.base.Preconditions.checkNotNull;
import com.google.protobuf.nano.CodedInputByteBufferNano;
import com.google.protobuf.nano.MessageNano;
import io.grpc.MethodDescriptor.Marshaller;
import io.grpc.Status;
-import java.io.ByteArrayOutputStream;
+import io.grpc.internal.IoUtils;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
/**
* Utility methods for using nano proto with grpc.
@@ -50,7 +48,7 @@ public class NanoUtils {
try {
// TODO(simonma): Investigate whether we can do 0-copy here.
CodedInputByteBufferNano input =
- CodedInputByteBufferNano.newInstance(toByteArray(stream));
+ CodedInputByteBufferNano.newInstance(IoUtils.toByteArray(stream));
input.setSizeLimit(Integer.MAX_VALUE);
T message = factory.newInstance();
message.mergeFrom(input);
@@ -62,28 +60,4 @@ public class NanoUtils {
}
};
}
-
- // Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta)
- private static byte[] toByteArray(InputStream in) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- copy(in, out);
- return out.toByteArray();
- }
-
- // Copied from guava com.google.common.io.ByteStreams because its API is unstable (beta)
- private static long copy(InputStream from, OutputStream to) throws IOException {
- 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;
- }
}