Source:
public void beforeStart(ClientCallStreamObserver<InsertObjectRequest> requestObserver) { requestObserver.setOnReadyHandler( new Runnable() { @Override public void run() { if (objectFinalized) { return; } try { chunkData = readRequestData(); } catch (IOException e) { error = new IOException(String.format("Failed to for '%s'", resourceId), e); return; } InsertObjectRequest.Builder requestBuilder = InsertObjectRequest.newBuilder() .setUploadId(uploadId) .setWriteOffset(writeOffset); if (chunkData.size() > 0) { ChecksummedData.Builder requestDataBuilder = ChecksummedData.newBuilder().setContent(chunkData); if (checksumsEnabled) { Hasher chunkHasher = Hashing.crc32c().newHasher(); for (ByteBuffer buffer : chunkData.asReadOnlyByteBufferList()) { chunkHasher.putBytes(buffer); } for (ByteBuffer buffer : chunkData.asReadOnlyByteBufferList()) { objectHasher.putBytes(buffer); } requestDataBuilder.setCrc32C( UInt32Value.newBuilder().setValue(chunkHasher.hash().asInt())); } requestBuilder.setChecksummedData(requestDataBuilder); } if (objectFinalized) { requestBuilder.setFinishWrite(true); if (checksumsEnabled) { requestBuilder.setObjectChecksums( ObjectChecksums.newBuilder() .setCrc32C( UInt32Value.newBuilder().setValue(objectHasher.hash().asInt()))); } } requestObserver.onNext(requestBuilder.build()); if (objectFinalized) { requestObserver.onCompleted(); } } private ByteString readRequestData() throws IOException { ByteString data = ByteString.readFrom(ByteStreams.limit(pipeSource, MAX_BYTES_PER_MESSAGE)); pipeSource.mark(1); objectFinalized = data.size() < MAX_BYTES_PER_MESSAGE || pipeSource.read() == -1; pipeSource.reset(); return data; } }); }

Target:
public void beforeStart(ClientCallStreamObserver<InsertObjectRequest> requestObserver) { requestObserver.setOnReadyHandler( new Runnable() { @Override public void run() { if (objectFinalized) { return; } try { chunkData = readRequestData(); } catch (IOException e) { error = new IOException( String.format("Failed to read chunk for '%s'", resourceId), e); return; } InsertObjectRequest.Builder requestBuilder = InsertObjectRequest.newBuilder() .setUploadId(uploadId) .setWriteOffset(writeOffset); if (chunkData.size() > 0) { ChecksummedData.Builder requestDataBuilder = ChecksummedData.newBuilder().setContent(chunkData); if (checksumsEnabled) { Hasher chunkHasher = Hashing.crc32c().newHasher(); for (ByteBuffer buffer : chunkData.asReadOnlyByteBufferList()) { chunkHasher.putBytes(buffer); } for (ByteBuffer buffer : chunkData.asReadOnlyByteBufferList()) { objectHasher.putBytes(buffer); } requestDataBuilder.setCrc32C( UInt32Value.newBuilder().setValue(chunkHasher.hash().asInt())); } requestBuilder.setChecksummedData(requestDataBuilder); } if (objectFinalized) { requestBuilder.setFinishWrite(true); if (checksumsEnabled) { requestBuilder.setObjectChecksums( ObjectChecksums.newBuilder() .setCrc32C( UInt32Value.newBuilder().setValue(objectHasher.hash().asInt()))); } } requestObserver.onNext(requestBuilder.build()); if (objectFinalized) { requestObserver.onCompleted(); } } private ByteString readRequestData() throws IOException { ByteString data = ByteString.readFrom(ByteStreams.limit(pipeSource, MAX_BYTES_PER_MESSAGE)); pipeSource.mark(1); objectFinalized = data.size() < MAX_BYTES_PER_MESSAGE || pipeSource.read() == -1; pipeSource.reset(); return data; } }); }