GoogleCloudStorageWriteChannel extends AbstractGoogleAsyncWriteChannel<Insert, StorageObject> implements GoogleCloudStorageItemInfo.Provider { @Override public Insert createRequest(InputStreamContent inputStream) throws IOException { StorageObject object = new StorageObject() .setContentEncoding(createOptions.getContentEncoding()) .setMetadata(encodeMetadata(createOptions.getMetadata())) .setName(resourceId.getObjectName()); Insert insert = gcs.objects() .insert(resourceId.getBucketName(), object, inputStream) .setName(resourceId.getObjectName()) .setKmsKeyName(createOptions.getKmsKeyName()); writeConditions.apply(insert); if (insert.getMediaHttpUploader() != null) { insert .getMediaHttpUploader() .setDirectUploadEnabled(isDirectUploadEnabled()) .setProgressListener( new LoggingMediaHttpUploaderProgressListener( resourceId.getObjectName(), MIN_LOGGING_INTERVAL_MS)); } return insert; } GoogleCloudStorageWriteChannel(
      Storage gcs,
      ClientRequestHelper<StorageObject> requestHelper,
      ExecutorService uploadThreadPool,
      AsyncWriteChannelOptions channelOptions,
      StorageResourceId resourceId,
      CreateObjectOptions createOptions,
      ObjectWriteConditions writeConditions); @Override Insert createRequest(InputStreamContent inputStream); @Override void handleResponse(StorageObject response); @Override StorageObject createResponseFromException(IOException e); @Override GoogleCloudStorageItemInfo getItemInfo();  }
@Test public void createRequest_shouldSetKmsKeyName() throws IOException { String kmsKeyName = "testKmsKey"; GoogleCloudStorageWriteChannel writeChannel = new GoogleCloudStorageWriteChannel( new Storage(HTTP_TRANSPORT, JSON_FACTORY, r -> {}), new ClientRequestHelper<>(), newDirectExecutorService(), AsyncWriteChannelOptions.DEFAULT, new StorageResourceId(BUCKET_NAME, OBJECT_NAME), CreateObjectOptions.DEFAULT_NO_OVERWRITE.toBuilder().setKmsKeyName(kmsKeyName).build(), ObjectWriteConditions.NONE); Storage.Objects.Insert request = writeChannel.createRequest( new InputStreamContent("plain/text", new ByteArrayInputStream(new byte[0]))); assertThat(request.getKmsKeyName()).isEqualTo(kmsKeyName); }