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


Java BlobInfo类代码示例

本文整理汇总了Java中com.google.cloud.storage.BlobInfo的典型用法代码示例。如果您正苦于以下问题:Java BlobInfo类的具体用法?Java BlobInfo怎么用?Java BlobInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BlobInfo类属于com.google.cloud.storage包,在下文中一共展示了BlobInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testWritableOutputStreamWithAutoCreateOnNullBlob

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Test
public void testWritableOutputStreamWithAutoCreateOnNullBlob() throws Exception {
	String location = "gs://test-spring/test";
	Storage storage = mock(Storage.class);
	BlobId blobId = BlobId.of("test-spring", "test");
	when(storage.get(blobId)).thenReturn(null);
	BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
	WriteChannel writeChannel = mock(WriteChannel.class);
	Blob blob = mock(Blob.class);
	when(blob.writer()).thenReturn(writeChannel);
	when(storage.create(blobInfo)).thenReturn(blob);

	GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
	GoogleStorageResourceObject spyResource = spy(resource);
	doReturn(this.bucketResource).when(spyResource).getBucket();
	OutputStream os = spyResource.getOutputStream();
	Assert.assertNotNull(os);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:19,代码来源:GoogleStorageTests.java

示例2: write

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Override
public void write(InputStream inputStream, String destination) throws IOException {
	String[] tokens = getBucketAndObjectFromPath(destination);
	Assert.state(tokens.length == 2, "Can only write to files, not buckets.");

	BlobInfo gcsBlobInfo = BlobInfo.newBuilder(BlobId.of(tokens[0], tokens[1])).build();

	try (InputStream is = inputStream) {
		try (WriteChannel channel = this.gcs.writer(gcsBlobInfo)) {
			channel.write(ByteBuffer.wrap(StreamUtils.copyToByteArray(is)));
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:14,代码来源:GcsSession.java

示例3: uploadFile

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
@SuppressWarnings("deprecation")
public String uploadFile(Part filePart, final String bucketName) throws IOException {
  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = filePart.getSubmittedFileName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          filePart.getInputStream());
  logger.log(
      Level.INFO, "Uploaded file {0} as {1}", new Object[]{
          filePart.getSubmittedFileName(), fileName});
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:27,代码来源:CloudStorageHelper.java

示例4: store

import com.google.cloud.storage.BlobInfo; //导入依赖的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

示例5: testWritableOutputStreamWithAutoCreateOnNonExistantBlob

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Test
public void testWritableOutputStreamWithAutoCreateOnNonExistantBlob()
		throws Exception {
	String location = "gs://test-spring/test";
	Storage storage = mock(Storage.class);
	BlobId blobId = BlobId.of("test-spring", "test");
	Blob nonExistantBlob = mock(Blob.class);
	when(nonExistantBlob.exists()).thenReturn(false);
	when(storage.get(blobId)).thenReturn(nonExistantBlob);
	BlobInfo blobInfo = BlobInfo.newBuilder(blobId).build();
	WriteChannel writeChannel = mock(WriteChannel.class);
	Blob blob = mock(Blob.class);
	when(blob.writer()).thenReturn(writeChannel);
	when(storage.create(blobInfo)).thenReturn(blob);


	GoogleStorageResourceObject resource = new GoogleStorageResourceObject(storage, location);
	GoogleStorageResourceObject spyResource = spy(resource);
	doReturn(this.bucketResource).when(spyResource).getBucket();
	OutputStream os = spyResource.getOutputStream();
	Assert.assertNotNull(os);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:23,代码来源:GoogleStorageTests.java

示例6: uploadFile

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
@SuppressWarnings("deprecation")
public String uploadFile(Part filePart, final String bucketName) throws IOException {
  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = filePart.getSubmittedFileName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          filePart.getInputStream());
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:24,代码来源:CloudStorageHelper.java

示例7: uploadFile

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  @SuppressWarnings("deprecation")
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  logger.log(Level.INFO, "Uploaded file {0} as {1}", new Object[]{
      fileStream.getName(), fileName});
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:29,代码来源:CloudStorageHelper.java

示例8: uploadFile

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
@SuppressWarnings("deprecation")
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:27,代码来源:CloudStorageHelper.java

示例9: uploadFile

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
 * environment variable, appending a timestamp to end of the uploaded filename.
 */
public String uploadFile(FileItemStream fileStream, final String bucketName)
    throws IOException, ServletException {
  checkFileExtension(fileStream.getName());

  DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
  DateTime dt = DateTime.now(DateTimeZone.UTC);
  String dtString = dt.toString(dtf);
  final String fileName = fileStream.getName() + dtString;

  // the inputstream is closed by default, so we don't need to close it here
  @SuppressWarnings("deprecation")
  BlobInfo blobInfo =
      storage.create(
          BlobInfo
              .newBuilder(bucketName, fileName)
              // Modify access list to allow all users with link to read file
              .setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER))))
              .build(),
          fileStream.openStream());
  // return the public download link
  return blobInfo.getMediaLink();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:27,代码来源:CloudStorageHelper.java

示例10: doPost

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException,
    ServletException {
  final Part filePart = req.getPart("file");
  final String fileName = filePart.getSubmittedFileName();

  // Modify access list to allow all users with link to read file
  List<Acl> acls = new ArrayList<>();
  acls.add(Acl.of(Acl.User.ofAllUsers(), Acl.Role.READER));
  // the inputstream is closed by default, so we don't need to close it here
  Blob blob =
      storage.create(
          BlobInfo.newBuilder(BUCKET_NAME, fileName).setAcl(acls).build(),
          filePart.getInputStream());

  // return the public download link
  resp.getWriter().print(blob.getMediaLink());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:UploadServlet.java

示例11: createSignedUrl

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
/**
 * Creates a signed URL to an object if it exists. This method will fail if this storage resource
 * was not created using service account credentials.
 * @param timeUnit the time unit used to determine how long the URL is valid.
 * @param timePeriods the number of periods to determine how long the URL is valid.
 * @return the URL if the object exists, and null if it does not.
 * @throws IOException
 */
public URL createSignedUrl(TimeUnit timeUnit, long timePeriods) throws IOException {
	Blob blob = this.getGoogleStorageObject();
	if (blob == null) {
		return null;
	}
	return this.storage.signUrl(
			BlobInfo.newBuilder(blob.getBucket(), blob.getName()).build(),
			timePeriods, timeUnit);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:18,代码来源:GoogleStorageResourceObject.java

示例12: createBlob

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
private Blob createBlob() throws IOException {
	GoogleStorageResourceBucket bucket = getBucket();
	if (!bucket.exists()) {
		bucket.createBucket();
	}
	return this.storage.create(BlobInfo.newBuilder(getBlobId()).build());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:8,代码来源:GoogleStorageResourceObject.java

示例13: list

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Override
public BlobInfo[] list(String path) throws IOException {
	// TODO(joaomartins): Only supports listing buckets, not folders.

	Collection<BlobInfo> blobs = new ArrayList<>();

	for (Blob blob : this.gcs.list(path).iterateAll()) {
		blobs.add(blob);
	}

	return blobs.toArray(new BlobInfo[blobs.size()]);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:13,代码来源:GcsSession.java

示例14: listNames

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Override
public String[] listNames(String path) throws IOException {
	List<String> names = Stream.of(list(path))
			.map(BlobInfo::getName)
			.collect(Collectors.toList());

	return names.toArray(new String[names.size()]);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:9,代码来源:GcsSession.java

示例15: testNewFiles

import com.google.cloud.storage.BlobInfo; //导入依赖的package包/类
@Test
public void testNewFiles() throws IOException {
	File testFile = this.temporaryFolder.newFile("benfica");

	BlobInfo expectedCreateBlobInfo =
			BlobInfo.newBuilder(BlobId.of("testGcsBucket", "benfica.writing")).build();
	WriteChannel writeChannel = mock(WriteChannel.class);
	willAnswer(invocationOnMock -> writeChannel).given(GCS)
			.writer(eq(expectedCreateBlobInfo));
	willAnswer(invocationOnMock -> 10).given(writeChannel).write(isA(ByteBuffer.class));

	CopyWriter copyWriter = mock(CopyWriter.class);
	ArgumentCaptor<Storage.CopyRequest> copyRequestCaptor = ArgumentCaptor.forClass(Storage.CopyRequest.class);
	willAnswer(invocationOnMock -> copyWriter).given(GCS).copy(isA(Storage.CopyRequest.class));

	willAnswer(invocationOnMock -> true).given(GCS)
			.delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));

	this.channel.send(new GenericMessage<Object>(testFile));

	verify(GCS, times(1)).writer(eq(expectedCreateBlobInfo));
	verify(GCS, times(1)).copy(copyRequestCaptor.capture());
	verify(GCS, times(1)).delete(eq(BlobId.of("testGcsBucket", "benfica.writing")));

	Storage.CopyRequest expectedCopyRequest = copyRequestCaptor.getValue();
	assertThat(expectedCopyRequest.getSource()).isEqualTo(BlobId.of("testGcsBucket", "benfica.writing"));
	assertThat(expectedCopyRequest.getTarget().getBlobId()).isEqualTo(BlobId.of("testGcsBucket", "benfica"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:29,代码来源:GcsMessageHandlerTests.java


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