| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 940999d commit 97b1efc
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -346,6 +346,14 @@ public static BlobTargetOption metagenerationNotMatch() { | |||
| 346 | 346 | return new BlobTargetOption(StorageRpc.Option.IF_METAGENERATION_NOT_MATCH); | |
| 347 | 347 | } | |
| 348 | 348 | ||
| 349 | + /** | ||
| 350 | + * Returns an option for blob's data disabledGzipContent. If this option is used, the request | ||
| 351 | + * will create a blob with disableGzipContent; at present, this is only for upload. | ||
| 352 | + */ | ||
| 353 | + public static BlobTargetOption disableGzipContent() { | ||
| 354 | + return new BlobTargetOption(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); | ||
| 355 | + } | ||
| 356 | + | ||
| 349 | 357 | /** | |
| 350 | 358 | * Returns an option to set a customer-supplied AES256 key for server-side encryption of the | |
| 351 | 359 | * blob. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,6 +287,9 @@ public StorageObject create( | |||
| 287 | 287 | storageObject, | |
| 288 | 288 | new InputStreamContent(storageObject.getContentType(), content)); | |
| 289 | 289 | insert.getMediaHttpUploader().setDirectUploadEnabled(true); | |
| 290 | + Boolean disableGzipContent = Option.IF_DISABLE_GZIP_CONTENT.getBoolean(options); | ||
| 291 | + if (disableGzipContent != null) | ||
| 292 | + insert.getMediaHttpUploader().setDisableGZipContent(disableGzipContent); | ||
| 290 | 293 | setEncryptionHeaders(insert.getRequestHeaders(), ENCRYPTION_KEY_PREFIX, options); | |
| 291 | 294 | return insert | |
| 292 | 295 | .setProjection(DEFAULT_PROJECTION) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,6 +48,7 @@ enum Option { | |||
| 48 | 48 | IF_SOURCE_METAGENERATION_NOT_MATCH("ifSourceMetagenerationNotMatch"), | |
| 49 | 49 | IF_SOURCE_GENERATION_MATCH("ifSourceGenerationMatch"), | |
| 50 | 50 | IF_SOURCE_GENERATION_NOT_MATCH("ifSourceGenerationNotMatch"), | |
| 51 | + IF_DISABLE_GZIP_CONTENT("disableGzipContent"), | ||
| 51 | 52 | PREFIX("prefix"), | |
| 52 | 53 | MAX_RESULTS("maxResults"), | |
| 53 | 54 | PAGE_TOKEN("pageToken"), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -154,6 +154,8 @@ public class StorageImplTest { | |||
| 154 | 154 | private static final BlobTargetOption BLOB_TARGET_GENERATION = BlobTargetOption.generationMatch(); | |
| 155 | 155 | private static final BlobTargetOption BLOB_TARGET_METAGENERATION = | |
| 156 | 156 | BlobTargetOption.metagenerationMatch(); | |
| 157 | + private static final BlobTargetOption BLOB_TARGET_DISABLE_GZIP_CONTENT = | ||
| 158 | + BlobTargetOption.disableGzipContent(); | ||
| 157 | 159 | private static final BlobTargetOption BLOB_TARGET_NOT_EXIST = BlobTargetOption.doesNotExist(); | |
| 158 | 160 | private static final BlobTargetOption BLOB_TARGET_PREDEFINED_ACL = | |
| 159 | 161 | BlobTargetOption.predefinedAcl(Storage.PredefinedAcl.PRIVATE); | |
@@ -162,6 +164,8 @@ public class StorageImplTest { | |||
| 162 | 164 | StorageRpc.Option.IF_METAGENERATION_MATCH, BLOB_INFO1.getMetageneration(), | |
| 163 | 165 | StorageRpc.Option.IF_GENERATION_MATCH, 0L, | |
| 164 | 166 | StorageRpc.Option.PREDEFINED_ACL, BUCKET_TARGET_PREDEFINED_ACL.getValue()); | |
| 167 | + private static final Map<StorageRpc.Option, ?> BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT = | ||
| 168 | + ImmutableMap.of(StorageRpc.Option.IF_DISABLE_GZIP_CONTENT, true); | ||
| 165 | 169 | private static final Map<StorageRpc.Option, ?> BLOB_TARGET_OPTIONS_UPDATE = | |
| 166 | 170 | ImmutableMap.of( | |
| 167 | 171 | StorageRpc.Option.IF_METAGENERATION_MATCH, BLOB_INFO1.getMetageneration(), | |
@@ -545,6 +549,32 @@ public void testCreateBlobWithOptions() throws IOException { | |||
| 545 | 549 | assertEquals(-1, byteStream.read(streamBytes)); | |
| 546 | 550 | } | |
| 547 | 551 | ||
| 552 | + @Test | ||
| 553 | + public void testCreateBlobWithDisabledGzipContent() throws IOException { | ||
| 554 | + Capture<ByteArrayInputStream> capturedStream = Capture.newInstance(); | ||
| 555 | + EasyMock.expect( | ||
| 556 | + storageRpcMock.create( | ||
| 557 | + EasyMock.eq( | ||
| 558 | + BLOB_INFO1 | ||
| 559 | + .toBuilder() | ||
| 560 | + .setMd5(CONTENT_MD5) | ||
| 561 | + .setCrc32c(CONTENT_CRC32C) | ||
| 562 | + .build() | ||
| 563 | + .toPb()), | ||
| 564 | + EasyMock.capture(capturedStream), | ||
| 565 | + EasyMock.eq(BLOB_TARGET_OPTIONS_CREATE_DISABLE_GZIP_CONTENT))) | ||
| 566 | + .andReturn(BLOB_INFO1.toPb()); | ||
| 567 | + EasyMock.replay(storageRpcMock); | ||
| 568 | + initializeService(); | ||
| 569 | + Blob blob = storage.create(BLOB_INFO1, BLOB_CONTENT, BLOB_TARGET_DISABLE_GZIP_CONTENT); | ||
| 570 | + assertEquals(expectedBlob1, blob); | ||
| 571 | + ByteArrayInputStream byteStream = capturedStream.getValue(); | ||
| 572 | + byte[] streamBytes = new byte[BLOB_CONTENT.length]; | ||
| 573 | + assertEquals(BLOB_CONTENT.length, byteStream.read(streamBytes)); | ||
| 574 | + assertArrayEquals(BLOB_CONTENT, streamBytes); | ||
| 575 | + assertEquals(-1, byteStream.read(streamBytes)); | ||
| 576 | + } | ||
| 577 | + | ||
| 548 | 578 | @Test | |
| 549 | 579 | public void testCreateBlobWithEncryptionKey() throws IOException { | |
| 550 | 580 | Capture<ByteArrayInputStream> capturedStream = Capture.newInstance(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments