本文整理了Java中com.google.cloud.storage.Blob.getContentType()
方法的一些代码示例,展示了Blob.getContentType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.getContentType()
方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:getContentType
暂无
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateBlobStream() {
String blobName = "test-create-blob-stream";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).build();
ByteArrayInputStream stream = new ByteArrayInputStream(BLOB_STRING_CONTENT.getBytes(UTF_8));
Blob remoteBlob = storage.create(blob, stream);
assertNotNull(remoteBlob);
assertEquals(blob.getBucket(), remoteBlob.getBucket());
assertEquals(blob.getName(), remoteBlob.getName());
assertEquals(blob.getContentType(), remoteBlob.getContentType());
byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertEquals(BLOB_STRING_CONTENT, new String(readBytes, UTF_8));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdateBlobs() {
String sourceBlobName1 = "test-update-blobs-1";
String sourceBlobName2 = "test-update-blobs-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteBlob1 = storage.create(sourceBlob1);
Blob remoteBlob2 = storage.create(sourceBlob2);
assertNotNull(remoteBlob1);
assertNotNull(remoteBlob2);
List<Blob> updatedBlobs =
storage.update(
remoteBlob1.toBuilder().setContentType(CONTENT_TYPE).build(),
remoteBlob2.toBuilder().setContentType(CONTENT_TYPE).build());
assertEquals(sourceBlob1.getBucket(), updatedBlobs.get(0).getBucket());
assertEquals(sourceBlob1.getName(), updatedBlobs.get(0).getName());
assertEquals(CONTENT_TYPE, updatedBlobs.get(0).getContentType());
assertEquals(sourceBlob2.getBucket(), updatedBlobs.get(1).getBucket());
assertEquals(sourceBlob2.getName(), updatedBlobs.get(1).getName());
assertEquals(CONTENT_TYPE, updatedBlobs.get(1).getContentType());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetBlobSelectedFields() {
String blobName = "test-get-selected-fields-blob";
BlobInfo blob =
BlobInfo.newBuilder(BUCKET, blobName)
.setContentType(CONTENT_TYPE)
.setMetadata(ImmutableMap.of("k", "v"))
.build();
assertNotNull(storage.create(blob));
Blob remoteBlob =
storage.get(blob.getBlobId(), Storage.BlobGetOption.fields(BlobField.METADATA));
assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
assertEquals(ImmutableMap.of("k", "v"), remoteBlob.getMetadata());
assertNull(remoteBlob.getContentType());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdateBlobsFail() {
String sourceBlobName1 = "test-update-blobs-fail-1";
String sourceBlobName2 = "test-update-blobs-fail-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
BlobInfo remoteBlob1 = storage.create(sourceBlob1);
assertNotNull(remoteBlob1);
List<Blob> updatedBlobs =
storage.update(
remoteBlob1.toBuilder().setContentType(CONTENT_TYPE).build(),
sourceBlob2.toBuilder().setContentType(CONTENT_TYPE).build());
assertEquals(sourceBlob1.getBucket(), updatedBlobs.get(0).getBucket());
assertEquals(sourceBlob1.getName(), updatedBlobs.get(0).getName());
assertEquals(CONTENT_TYPE, updatedBlobs.get(0).getContentType());
assertNull(updatedBlobs.get(1));
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(BUCKET, remoteBlob.getBucket());
assertTrue(blobSet.contains(remoteBlob.getName()));
assertNull(remoteBlob.getContentType());
代码示例来源:origin: googleapis/google-cloud-java
assertTrue(blobSet.contains(remoteBlob.getName()));
assertTrue(remoteBlob.getKmsKeyName().startsWith(kmsKeyOneResourcePath));
assertNull(remoteBlob.getContentType());
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetBlobKmsKeyNameField() {
String blobName = "test-get-selected-kms-key-name-field-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).build();
assertNotNull(storage.create(blob, Storage.BlobTargetOption.kmsKeyName(kmsKeyOneResourcePath)));
Blob remoteBlob =
storage.get(blob.getBlobId(), Storage.BlobGetOption.fields(BlobField.KMS_KEY_NAME));
assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
assertTrue(remoteBlob.getKmsKeyName().startsWith(kmsKeyOneResourcePath));
assertNull(remoteBlob.getContentType());
}
代码示例来源:origin: googleapis/google-cloud-java
assertTrue(blobSet.contains(remoteBlob.getName()));
assertEquals(metadata, remoteBlob.getMetadata());
assertNull(remoteBlob.getContentType());
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testGetBlobEmptySelectedFields() {
String blobName = "test-get-empty-selected-fields-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).build();
assertNotNull(storage.create(blob));
Blob remoteBlob = storage.get(blob.getBlobId(), Storage.BlobGetOption.fields());
assertEquals(blob.getBlobId(), remoteBlob.getBlobId());
assertNull(remoteBlob.getContentType());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testComposeBlob() {
String sourceBlobName1 = "test-compose-blob-source-1";
String sourceBlobName2 = "test-compose-blob-source-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteSourceBlob1 = storage.create(sourceBlob1, BLOB_BYTE_CONTENT);
Blob remoteSourceBlob2 = storage.create(sourceBlob2, BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob1);
assertNotNull(remoteSourceBlob2);
String targetBlobName = "test-compose-blob-target";
BlobInfo targetBlob = BlobInfo.newBuilder(BUCKET, targetBlobName).build();
Storage.ComposeRequest req =
Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob);
Blob remoteTargetBlob = storage.compose(req);
assertNotNull(remoteTargetBlob);
assertEquals(targetBlob.getName(), remoteTargetBlob.getName());
assertEquals(targetBlob.getBucket(), remoteTargetBlob.getBucket());
assertNull(remoteTargetBlob.getContentType());
byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
byte[] composedBytes = Arrays.copyOf(BLOB_BYTE_CONTENT, BLOB_BYTE_CONTENT.length * 2);
System.arraycopy(
BLOB_BYTE_CONTENT, 0, composedBytes, BLOB_BYTE_CONTENT.length, BLOB_BYTE_CONTENT.length);
assertArrayEquals(composedBytes, readBytes);
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(BUCKET, remoteBlob.getBucket());
if (remoteBlob.getName().equals(blobNames[1])) {
assertEquals(CONTENT_TYPE, remoteBlob.getContentType());
assertEquals(BLOB_BYTE_CONTENT.length, (long) remoteBlob.getSize());
assertFalse(remoteBlob.isDirectory());
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testComposeBlobWithContentType() {
String sourceBlobName1 = "test-compose-blob-with-content-type-source-1";
String sourceBlobName2 = "test-compose-blob-with-content-type-source-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteSourceBlob1 = storage.create(sourceBlob1, BLOB_BYTE_CONTENT);
Blob remoteSourceBlob2 = storage.create(sourceBlob2, BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob1);
assertNotNull(remoteSourceBlob2);
String targetBlobName = "test-compose-blob-with-content-type-target";
BlobInfo targetBlob =
BlobInfo.newBuilder(BUCKET, targetBlobName).setContentType(CONTENT_TYPE).build();
Storage.ComposeRequest req =
Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob);
Blob remoteTargetBlob = storage.compose(req);
assertNotNull(remoteTargetBlob);
assertEquals(targetBlob.getName(), remoteTargetBlob.getName());
assertEquals(targetBlob.getBucket(), remoteTargetBlob.getBucket());
assertEquals(CONTENT_TYPE, remoteTargetBlob.getContentType());
byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
byte[] composedBytes = Arrays.copyOf(BLOB_BYTE_CONTENT, BLOB_BYTE_CONTENT.length * 2);
System.arraycopy(
BLOB_BYTE_CONTENT, 0, composedBytes, BLOB_BYTE_CONTENT.length, BLOB_BYTE_CONTENT.length);
assertArrayEquals(composedBytes, readBytes);
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdateBlob() {
String blobName = "test-update-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
Blob updatedBlob = remoteBlob.toBuilder().setContentType(CONTENT_TYPE).build().update();
assertNotNull(updatedBlob);
assertEquals(blob.getName(), updatedBlob.getName());
assertEquals(blob.getBucket(), updatedBlob.getBucket());
assertEquals(CONTENT_TYPE, updatedBlob.getContentType());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobNoContentType() {
String sourceBlobName = "test-copy-blob-no-content-type-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-no-content-type-target";
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo target = BlobInfo.newBuilder(BUCKET, targetBlobName).setMetadata(metadata).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertNull(copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlob() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob =
BlobInfo.newBuilder(source).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req = Storage.CopyRequest.of(source, BlobId.of(BUCKET, targetBlobName));
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-update-metadata-target";
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo target =
BlobInfo.newBuilder(BUCKET, targetBlobName)
.setContentType(CONTENT_TYPE)
.setMetadata(metadata)
.build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertNotNull(copyWriter.getResult().getKmsKeyName());
assertTrue(copyWriter.getResult().getKmsKeyName().startsWith(kmsKeyOneResourcePath));
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCopyBlobWithPredefinedAcl() {
String sourceBlobName = "test-copy-blob-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo blob =
BlobInfo.newBuilder(source).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-target";
Storage.CopyRequest req =
Storage.CopyRequest.newBuilder()
.setSource(source)
.setTarget(
BlobId.of(BUCKET, targetBlobName),
Storage.BlobTargetOption.predefinedAcl(Storage.PredefinedAcl.PUBLIC_READ))
.build();
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertNotNull(copyWriter.getResult().getAcl(User.ofAllUsers()));
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertArrayEquals(
BLOB_BYTE_CONTENT,
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertArrayEquals(BLOB_BYTE_CONTENT, copyWriter.getResult().getContent());
assertEquals(metadata, copyWriter.getResult().getMetadata());
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(sourceBlob2.getBucket(), remoteUpdatedBlob2.getBucket());
assertEquals(sourceBlob2.getName(), remoteUpdatedBlob2.getName());
assertEquals(updatedBlob1.getContentType(), remoteUpdatedBlob1.getContentType());
assertEquals(updatedBlob2.getContentType(), remoteUpdatedBlob2.getContentType());
内容来源于网络,如有侵权,请联系作者删除!