Source:
private Object doResumableUpload() throws IOException { if (writeOffset > 0) { writeOffset = getCommittedWriteSize(uploadId); } responseObserver = new InsertChunkResponseObserver(uploadId, writeOffset); StreamObserver<InsertObjectRequest> requestStreamObserver = stub.withDeadlineAfter(WRITE_STREAM_TIMEOUT.toMillis(), MILLISECONDS) .insertObject(responseObserver); try { responseObserver.ready.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException( String.format( "Streaming RPC failed to become ready for resumable upload for '%s'", getResourceString()), e); } boolean objectFinalized = false; while (!objectFinalized) { InsertObjectRequest insertRequest; if (dataChunkMap.size() > 0 && dataChunkMap.lastKey() >= writeOffset) { insertRequest = buildRequestFromBufferedDataChunk(dataChunkMap, writeOffset); writeOffset += insertRequest.getChecksummedData().getContent().size(); } else { ByteString data = ByteString.readFrom(ByteStreams.limit(pipeSource, MAX_BYTES_PER_MESSAGE)); dataChunkMap.put(writeOffset, data); if (dataChunkMap.size() >= NUMBER_OF_REQUESTS_TO_RETAIN) { dataChunkMap.remove(dataChunkMap.firstKey()); } insertRequest = buildInsertRequest(writeOffset, data, false); writeOffset += data.size(); } requestStreamObserver.onNext(insertRequest); objectFinalized = insertRequest.getFinishWrite(); if (responseObserver.hasTransientError() || responseObserver.hasNonTransientError()) { requestStreamObserver.onError( responseObserver.hasTransientError() ? responseObserver.transientError : responseObserver.nonTransientError); break; } else if (objectFinalized) { requestStreamObserver.onCompleted(); } } try { responseObserver.done.await(); if (responseObserver.hasTransientError()) { throw new IOException(responseObserver.transientError); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return responseObserver.getResponseOrThrow(); }

Target:
private Object doResumableUpload() throws IOException, InterruptedException { if (writeOffset > 0) { writeOffset = getCommittedWriteSize(uploadId); } responseObserver = new InsertChunkResponseObserver(uploadId, writeOffset); StreamObserver<InsertObjectRequest> requestStreamObserver = stub.withDeadlineAfter(WRITE_STREAM_TIMEOUT.toMillis(), MILLISECONDS) .insertObject(responseObserver); try { responseObserver.ready.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException( String.format( "Streaming RPC failed to become ready for resumable upload for '%s'", getResourceString()), e); } boolean objectFinalized = false; while (!objectFinalized) { InsertObjectRequest insertRequest; if (dataChunkMap.size() > 0 && dataChunkMap.lastKey() >= writeOffset) { insertRequest = buildRequestFromBufferedDataChunk(dataChunkMap, writeOffset); writeOffset += insertRequest.getChecksummedData().getContent().size(); } else { ByteString data = ByteString.readFrom(ByteStreams.limit(pipeSource, MAX_BYTES_PER_MESSAGE)); dataChunkMap.put(writeOffset, data); if (dataChunkMap.size() >= NUMBER_OF_REQUESTS_TO_RETAIN) { dataChunkMap.remove(dataChunkMap.firstKey()); } insertRequest = buildInsertRequest(writeOffset, data, false); writeOffset += data.size(); } requestStreamObserver.onNext(insertRequest); objectFinalized = insertRequest.getFinishWrite(); if (responseObserver.hasTransientError() || responseObserver.hasNonTransientError()) { requestStreamObserver.onError( responseObserver.hasTransientError() ? responseObserver.transientError : responseObserver.nonTransientError); break; } else if (objectFinalized) { requestStreamObserver.onCompleted(); } } responseObserver.done.await(); if (responseObserver.hasTransientError()) { throw new IOException(responseObserver.transientError); } return responseObserver.getResponseOrThrow(); }