本文整理了Java中com.google.cloud.storage.Blob.exists()
方法的一些代码示例,展示了Blob.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Blob.exists()
方法的具体详情如下:
包路径:com.google.cloud.storage.Blob
类名称:Blob
方法名:exists
[英]Checks if this blob exists.
Example of checking if the blob exists.
boolean exists = blob.exists();else
// the blob was not found
}
}
[中]检查此blob是否存在。
检查blob是否存在的示例。
boolean exists = blob.exists();else
// the blob was not found
}
}
代码示例来源:origin: googleapis/google-cloud-java
/** Example of checking if the blob exists. */
// [TARGET exists(BlobSourceOption...)]
public boolean exists() {
// [START exists]
boolean exists = blob.exists();
if (exists) {
// the blob exists
} else {
// the blob was not found
}
// [END exists]
return exists;
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testExists_False() throws Exception {
Storage.BlobGetOption[] expectedOptions = {Storage.BlobGetOption.fields()};
expect(storage.getOptions()).andReturn(null);
expect(storage.get(BLOB_INFO.getBlobId(), expectedOptions)).andReturn(null);
replay(storage);
initializeBlob();
assertFalse(blob.exists());
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testExists_True() throws Exception {
initializeExpectedBlob(1);
Storage.BlobGetOption[] expectedOptions = {Storage.BlobGetOption.fields()};
expect(storage.getOptions()).andReturn(mockOptions);
expect(storage.get(expectedBlob.getBlobId(), expectedOptions)).andReturn(expectedBlob);
replay(storage);
initializeBlob();
assertTrue(blob.exists());
}
代码示例来源:origin: spring-cloud/spring-cloud-gcp
/**
* Returns the output stream for a Google Cloud Storage file.
* @return the object's output stream or {@code null} if the object doesn't exist and cannot be
* created
* @throws IOException if an issue occurs getting the OutputStream
*/
@Override
public OutputStream getOutputStream() throws IOException {
if (isBucket()) {
throw new IllegalStateException("Cannot open an output stream to a bucket: '" + this.location + "'");
}
else {
Blob blob = getBlob();
if (blob == null || !blob.exists()) {
if (!this.autoCreateFiles) {
throw new FileNotFoundException("The blob was not found: " + this.location);
}
blob = createBlob();
}
return Channels.newOutputStream(blob.writer());
}
}
代码示例来源:origin: org.springframework.cloud/spring-cloud-gcp-storage
/**
* Returns the output stream for a Google Cloud Storage file.
* @return the object's output stream or {@code null} if the object doesn't exist and cannot be
* created
* @throws IOException if an issue occurs getting the OutputStream
*/
@Override
public OutputStream getOutputStream() throws IOException {
if (isBucket()) {
throw new IllegalStateException("Cannot open an output stream to a bucket: '" + this.location + "'");
}
else {
Blob blob = getBlob();
if (blob == null || !blob.exists()) {
if (!this.autoCreateFiles) {
throw new FileNotFoundException("The blob was not found: " + this.location);
}
blob = createBlob();
}
return Channels.newOutputStream(blob.writer());
}
}
代码示例来源:origin: ai.h2o/h2o-persist-gcs
@Override
public boolean exists(String path) {
final String bk[] = split(path);
if (bk.length == 1) {
return storageProvider.getStorage().get(bk[0]).exists();
} else if (bk.length == 2) {
Blob blob = storageProvider.getStorage().get(bk[0], bk[1]);
return blob != null && blob.exists();
} else {
return false;
}
}
内容来源于网络,如有侵权,请联系作者删除!