本文整理汇总了Java中com.google.cloud.storage.Blob.exists方法的典型用法代码示例。如果您正苦于以下问题:Java Blob.exists方法的具体用法?Java Blob.exists怎么用?Java Blob.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.cloud.storage.Blob
的用法示例。
在下文中一共展示了Blob.exists方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
@Override
public boolean load(BuildCacheKey buildCacheKey, BuildCacheEntryReader buildCacheEntryReader)
throws BuildCacheException {
try {
Blob blob = cloudStorage.get(cacheKeyToBlobId(buildCacheKey));
if (blob == null || !blob.exists()) {
return false;
}
try (InputStream is = Channels.newInputStream(blob.reader())) {
buildCacheEntryReader.readFrom(is);
}
} catch (Exception e) {
logger.warn(
"Exception when trying to read from cloud storage, this usually means gcloud "
+ "auth application-default login has not been called. Builds may be slower.",
e);
return false;
}
return true;
}
示例2: store
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
@Override
public void store(BuildCacheKey buildCacheKey, BuildCacheEntryWriter buildCacheEntryWriter)
throws BuildCacheException {
Blob blob = cloudStorage.get(cacheKeyToBlobId(buildCacheKey));
if (blob == null || !blob.exists()) {
blob =
cloudStorage.create(
BlobInfo.newBuilder(cacheKeyToBlobId(buildCacheKey))
.setContentType(BUILD_CACHE_CONTENT_TYPE)
.build());
}
try (OutputStream os = Channels.newOutputStream(blob.writer())) {
buildCacheEntryWriter.writeTo(os);
} catch (IOException e) {
throw new UncheckedIOException("Error writing file from cloud storage.", e);
}
}
示例3: getScripts
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
/**
* Gives the raw JS Scripts sepcified
* @return list of raw JS Script data as strings
*/
public List<String> getScripts() {
if (Strings.isNullOrEmpty(gcsJSPath())) {
return new ArrayList<>();
}
String bucketName = gcsJSPath().replace("gs://", "").split("/")[0];
String prefixPath = gcsJSPath().replace("gs://" + bucketName + "/", "");
Bucket bucket = getStorageService().get(bucketName);
if (bucket == null || !bucket.exists()) {
throw new IllegalArgumentException(
"Bucket does not exist, or do not have adequate permissions");
}
ArrayList<String> filePaths = new ArrayList<>();
if (prefixPath.endsWith(".js")) {
filePaths.add(prefixPath);
} else {
Page<Blob> blobs = bucket.list(BlobListOption.prefix(prefixPath));
blobs.iterateAll().forEach((Blob blob) -> {
if (blob.getName().endsWith(".js")) {
filePaths.add(blob.getName());
}
});
}
List<String> scripts = new ArrayList<>();
for (String filePath : filePaths) {
Blob b = bucket.get(filePath);
if (b == null || !b.exists()) {
throw new IllegalArgumentException(
"File does not exist, or do not have adequate permissions");
}
scripts.add(new String(b.getContent()));
}
return scripts;
}
示例4: apply
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
@Override
public String apply(String gcspath) {
Storage storage = StorageOptions.getDefaultInstance().getService();
String bucketName = gcspath.replace("gs://", "").split("/")[0];
String blobName = gcspath.replace("gs://" + bucketName + "/", "");
Blob blob = storage.get(bucketName, blobName);
if (!blob.exists()) {
throw new IllegalArgumentException("File does not exists in gcs(" + gcspath + ")");
}
return new String(blob.getContent());
}
示例5: getOutputStream
import com.google.cloud.storage.Blob; //导入方法依赖的package包/类
@Override
public OutputStream getOutputStream() throws IOException {
Blob blob = getGoogleStorageObject();
if ((blob == null || !blob.exists()) && this.createBlobIfNotExists) {
blob = createBlob();
}
return Channels.newOutputStream(throwExceptionForNullBlob(blob).writer());
}