Source:
<code>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); <START> if (chunkData.size() > 0) { <END> ChecksummedData.Builder requestDataBuilder = ChecksummedData.newBuilder().setContent(chunkData); if (checksumsEnabled) { Hasher chunkHasher = Hashing.crc32c().newHasher(); for (ByteBuffer buffer : chunkData.asReadOnlyByteBufferList()) { chunkHasher.putBytes(buffer.duplicate()); objectHasher.putBytes(buffer.duplicate()); } 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 { bufferedPipeSource.mark(MAX_BYTES_PER_MESSAGE); ByteString data = ByteString.readFrom( ByteStreams.limit(bufferedPipeSource, MAX_BYTES_PER_MESSAGE)); objectFinalized = data.size() < MAX_BYTES_PER_MESSAGE || pipeSource.available() > 0; return data; } }); }</code><technical_language>do need duplicate call</technical_language>

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.duplicate()); objectHasher.putBytes(buffer.duplicate()); } 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 { pipeSource.mark(MAX_BYTES_PER_MESSAGE); ByteString data = ByteString.readFrom(ByteStreams.limit(pipeSource, MAX_BYTES_PER_MESSAGE)); objectFinalized = data.size() < MAX_BYTES_PER_MESSAGE || pipeSource.available() > 0; return data; } }); }