当前位置: 首页>>代码示例>>Java>>正文


Java Blob.exists方法代码示例

本文整理汇总了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;
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:21,代码来源:CloudStorageBuildCacheService.java

示例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);
  }
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:18,代码来源:CloudStorageBuildCacheService.java

示例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;
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:43,代码来源:JSTransform.java

示例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());
}
 
开发者ID:cobookman,项目名称:teleport,代码行数:15,代码来源:ValueProviderHelpers.java

示例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());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:9,代码来源:GoogleStorageResourceObject.java


注:本文中的com.google.cloud.storage.Blob.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。