use of build.buildfarm.common.grpc.DelegateServerCallStreamObserver in project bazel-buildfarm by bazelbuild.
the class ByteStreamService method newChunkObserver.
ServerCallStreamObserver<ByteString> newChunkObserver(ServerCallStreamObserver<ReadResponse> responseObserver) {
return new DelegateServerCallStreamObserver<ByteString, ReadResponse>(responseObserver) {
@Override
public void onNext(ByteString data) {
while (!data.isEmpty()) {
ByteString slice;
if (data.size() > CHUNK_SIZE) {
slice = data.substring(0, CHUNK_SIZE);
data = data.substring(CHUNK_SIZE);
} else {
slice = data;
data = ByteString.EMPTY;
}
responseObserver.onNext(ReadResponse.newBuilder().setData(slice).build());
}
}
@Override
public void onError(Throwable t) {
responseObserver.onError(t);
}
@Override
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
Aggregations