• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Bucket类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: mockStorage

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
@Bean
public static Storage mockStorage() throws Exception {
	Storage storage = mock(Storage.class);
	BlobId validBlob = BlobId.of("test-spring", "images/spring.png");
	Bucket mockedBucket = mock(Bucket.class);
	Blob mockedBlob = mock(Blob.class);
	WriteChannel writeChannel = mock(WriteChannel.class);
	when(mockedBlob.exists()).thenReturn(true);
	when(mockedBucket.exists()).thenReturn(true);
	when(mockedBlob.getSize()).thenReturn(4096L);
	when(storage.get(eq(validBlob))).thenReturn(mockedBlob);
	when(storage.get("test-spring")).thenReturn(mockedBucket);
	when(mockedBucket.getName()).thenReturn("test-spring");
	when(mockedBlob.writer()).thenReturn(writeChannel);
	return storage;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:17,代码来源:GoogleStorageTests.java


示例2: getListCellRendererComponent

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
@Override
public Component getListCellRendererComponent(
    JList<? extends Bucket> list,
    Bucket bucket,
    int index,
    boolean isSelected,
    boolean cellHasFocus) {
  setIcon(GoogleCloudToolsIcons.CLOUD_STORAGE_BUCKET);
  setText(bucket.getName());

  if (isSelected) {
    setBackground(list.getSelectionBackground());
    setForeground(list.getSelectionForeground());
  } else {
    setBackground(list.getBackground());
    setForeground(list.getForeground());
  }

  return this;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:21,代码来源:GcsBucketCellRenderer.java


示例3: showRightClickMenu

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
private void showRightClickMenu(MouseEvent event) {
  JPopupMenu rightClickMenu = new JPopupMenu();
  JMenuItem copyBucketNameMenuItem =
      new JMenuItem(GctBundle.message("gcs.content.explorer.right.click.menu.copy.bucket.text"));
  rightClickMenu.add(copyBucketNameMenuItem);

  int index = bucketList.locationToIndex(event.getPoint());
  Bucket bucket = bucketListModel.getElementAt(index);

  if (bucket != null) {
    copyBucketNameMenuItem.addActionListener(
        e ->
            UsageTrackerProvider.getInstance()
                .trackEvent(GctTracking.GCS_BUCKET_LIST_ACTION_COPY_BUCKET_NAME)
                .ping());
    copyBucketNameMenuItem.addActionListener(new CopyToClipboardActionListener(bucket.getName()));
    rightClickMenu.show(event.getComponent(), event.getX(), event.getY());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:20,代码来源:GcsBucketPanel.java


示例4: setupVirtualFileWithBucketMocks

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
static GcsBucketVirtualFile setupVirtualFileWithBucketMocks(
    GcsBucketVirtualFile gcsBucketVirtualFile) {
  Bucket bucket = mock(Bucket.class);
  Page<Blob> page = mock(Page.class);
  Iterable<Blob> blobIterable = mock(Iterable.class);
  Iterator<Blob> blobIterator = mock(Iterator.class);

  when(gcsBucketVirtualFile.getBucket()).thenReturn(bucket);
  when(bucket.list()).thenReturn(page);
  when(bucket.list(any(BlobListOption.class), any(BlobListOption.class))).thenReturn(page);
  when(page.iterateAll()).thenReturn(blobIterable);
  when(blobIterable.iterator()).thenReturn(blobIterator);

  return gcsBucketVirtualFile;
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:16,代码来源:GcsTestUtils.java


示例5: testCloudStorageSignUrl

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
@Test
public void testCloudStorageSignUrl() throws IOException {
  StorageClient storage = StorageClient.getInstance(IntegrationTestUtils.ensureDefaultApp());
  Bucket bucket = storage.bucket();
  Blob blob = createTextBlob(bucket, "Signed URL Test");
  URL url = blob.signUrl(3600, TimeUnit.SECONDS);
  try (InputStream in = url.openStream()) {
    String result = CharStreams.toString(new InputStreamReader(in));
    assertEquals("Signed URL Test", result);
  } finally {
    blob.delete();
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:StorageClientIT.java


示例6: testBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
private void testBucket(Bucket bucket) {
  assertEquals(IntegrationTestUtils.getStorageBucket(), bucket.getName());
  String fileName = createTextBlob(bucket, "Hello World").getName();

  Blob blob = bucket.get(fileName);
  byte[] content = blob.getContent();
  assertEquals("Hello World", new String(content));

  assertTrue(blob.delete());
  assertNull(bucket.get(fileName));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:12,代码来源:StorageClientIT.java


示例7: testBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
@Test
public void testBucket() throws IOException {
  FirebaseApp app = FirebaseApp.initializeApp(new FirebaseOptions.Builder()
      .setCredentials(GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()))
      .setStorageBucket("mock-bucket-name")
      .build());
  Storage mockStorage = Mockito.mock(Storage.class);
  Bucket mockBucket = Mockito.mock(Bucket.class);
  Mockito.when(mockStorage.get("mock-bucket-name")).thenReturn(mockBucket);
  StorageClient client = new StorageClient(app, mockStorage);
  assertSame(mockBucket, client.bucket());
  assertSame(mockBucket, client.bucket("mock-bucket-name"));
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:14,代码来源:StorageClientTest.java


示例8: getScripts

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


示例9: destroyBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
void destroyBucket(String name) {
    String bName = environment + name.replaceAll("\\.", "").toLowerCase();
    Bucket bukkit = storage.get(bName);
    if (bukkit != null) {
        for (Blob blob : this.listBlobs(name)) {
            storage.delete(blob.getBlobId());
        }
        try {
            storage.delete(bName);
        } catch (Exception e) {
            System.err.println("Cannot delete bucket " + name + " : " + e.getMessage());
        }
    }
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:15,代码来源:GoogleBlobStore.java


示例10: TestApp

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public TestApp() {
	try
	{
		HttpTransport httpTransport = new NetHttpTransport();             
		JacksonFactory jsonFactory = new JacksonFactory();
		//ComputeCredential credential = new ComputeCredential.Builder(httpTransport, jsonFactory).build();	
		GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);				            
		if (credential.createScopedRequired())
		    credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));           				            
		Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
		            .setApplicationName("oauth client")   
		            .build();				            
		Userinfoplus ui = service.userinfo().get().execute();
		System.out.println(ui.getEmail());



         // Using Google Cloud APIs
	  Storage  storage_service = StorageOptions.defaultInstance().service();
       
         Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
         while (bucketIterator.hasNext()) {
           System.out.println(bucketIterator.next());
         }	

	} 
	catch (Exception ex) {
		System.out.println("Error:  " + ex);
	}
}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:31,代码来源:TestApp.java


示例11: doGet

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws IOException {
	resp.setContentType("text/plain");
	resp.getWriter().println("Hello, world");
			
	HttpTransport httpTransport = new UrlFetchTransport();        
	JacksonFactory jsonFactory = new JacksonFactory();

	/*
	AppIdentityService appIdentity = AppIdentityServiceFactory.getAppIdentityService();    
	AppIdentityService.GetAccessTokenResult accessToken = appIdentity.getAccessToken(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));         
	GoogleCredential credential = new GoogleCredential.Builder()
		.setTransport(httpTransport)
		.setJsonFactory(jsonFactory).build();
    credential.setAccessToken(accessToken.getAccessToken());
	*/

	GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport,jsonFactory);    
	if (credential.createScopedRequired())
	    credential = credential.createScoped(Arrays.asList(Oauth2Scopes.USERINFO_EMAIL));           

	Oauth2 service = new Oauth2.Builder(httpTransport, jsonFactory, credential)
	    .setApplicationName("oauth client").build();

	Userinfoplus ui = service.userinfo().get().execute(); 
	resp.getWriter().println(ui.getEmail());
    

         // Using Google Cloud APIs
	  Storage  storage_service = StorageOptions.defaultInstance().service();
       
         Iterator<Bucket> bucketIterator = storage_service.list().iterateAll();
         while (bucketIterator.hasNext()) {
           System.out.println(bucketIterator.next());
         }		

}
 
开发者ID:salrashid123,项目名称:gcpsamples,代码行数:38,代码来源:TestServlet.java


示例12: main

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public static void main(String... args) throws Exception {
  // Instantiates a client
  Storage storage = StorageOptions.getDefaultInstance().getService();

  // The name for the new bucket
  String bucketName = args[0];  // "my-new-bucket";

  // Creates the new bucket
  Bucket bucket = storage.create(BucketInfo.of(bucketName));

  System.out.printf("Bucket %s created.%n", bucket.getName());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:QuickstartSample.java


示例13: loadBucketContents

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
private void loadBucketContents(@NotNull Bucket bucket) {
  FileEditorManager editorManager = FileEditorManager.getInstance(project);

  editorManager.openEditor(
      new OpenFileDescriptor(
          project,
          findOpenGcsVirtualFile(bucket).orElseGet(() -> new GcsBucketVirtualFile(bucket)),
          1 /*offset*/),
      true /*focusEditor*/);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:11,代码来源:GcsBucketPanel.java


示例14: findOpenGcsVirtualFile

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
/**
 * Searches for an open editor who's {@link VirtualFile} matches the bucket that was opened. This
 * prevents the same editor window being opened multiple times for the same bucket.
 */
private Optional<GcsBucketVirtualFile> findOpenGcsVirtualFile(@NotNull Bucket bucket) {
  FileEditorManager editorManager = FileEditorManager.getInstance(project);

  return Arrays.stream(editorManager.getOpenFiles())
      .filter(openFile -> openFile instanceof GcsBucketVirtualFile)
      .map(openGcsFile -> (GcsBucketVirtualFile) openGcsFile)
      .filter(openGcsFile -> openGcsFile.getBucket().equals(bucket))
      .findFirst();
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:14,代码来源:GcsBucketPanel.java


示例15: doListChildren

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
/**
 * Gets the list of child files of the current directory
 *
 * @return A list of file/folders
 * @throws Exception
 */
@Override protected String[] doListChildren() throws Exception {
  List<String> items = new ArrayList<>();
  Map<String, List<String>> folders = new HashMap<>();
  Bucket bucket = storage.get( getBucketName() );
  if ( bucket != null && bucket.exists() ) {
    folders.put( "", new ArrayList<>() );
    for ( Blob blob : bucket.list().iterateAll() ) {
      String path = blob.getName();
      boolean isDirectory = path.endsWith( DELIMITER );
      String parent = "";
      if ( path.contains( DELIMITER ) ) {
        parent = path.substring( 0, path.lastIndexOf( DELIMITER ) );
      }
      String[] parts = path.split( DELIMITER );
      String name = parts[ parts.length - 1 ];
      if ( isDirectory ) {
        folders.put( fixSlashes( path, false ), new ArrayList<>() );
        name = name.concat( DELIMITER );
        parent = path.substring( 0, path.lastIndexOf( DELIMITER ) );
        if ( parent.contains( DELIMITER ) ) {
          parent = parent.substring( 0, parent.lastIndexOf( DELIMITER ) );
        } else {
          parent = "";
        }
      }
      List<String> folderList = folders.getOrDefault( fixSlashes( parent, true ), new ArrayList<>() );
      folderList.add( name );
      folders.put( fixSlashes( parent, true ), folderList );
    }
    items = folders.getOrDefault( fixSlashes( getName().getPath(), true ), Collections.emptyList() );
  }

  return items.toArray( new String[ items.size() ] );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:41,代码来源:GoogleCloudStorageFileObject.java


示例16: getBlob

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
/**
 * Gets the blob from the Google Cloud Storage api for the file/folder
 *
 * @return The Blob that represents the file/folder
 */
public Blob getBlob() {
  URLFileName urlFileName = (URLFileName) this.getName();
  Bucket bucket = storage.get( urlFileName.getHostName() );
  if ( urlFileName.getPath().equals( DELIMITER ) ) {
    return null;
  }
  String stripped = urlFileName.getPath().substring( 1, urlFileName.getPath().length() );
  Blob blob = bucket.get( stripped );
  if ( blob == null ) {
    blob = bucket.get( stripped.concat( DELIMITER ) );
  }
  return blob;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:19,代码来源:GoogleCloudStorageFileObject.java


示例17: createTextBlob

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
private Blob createTextBlob(Bucket bucket, String contents) {
  String fileName = "data_" + System.currentTimeMillis() + ".txt";
  return bucket.create(fileName, contents.getBytes(), "text/plain");
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:5,代码来源:StorageClientIT.java


示例18: checkBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public Bucket checkBucket(String bucketName) {
  return Objects.requireNonNull(storage.get(bucketName, Storage.BucketGetOption.fields()),
          "No such bucket");
}
 
开发者ID:spotify,项目名称:spydra,代码行数:5,代码来源:GcpUtils.java


示例19: createBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public Bucket createBucket(String bucketName) {
  Bucket bucket = storage.create(BucketInfo.newBuilder(bucketName)
          .setLocation("europe-west1")
          .build());
  return bucket;
}
 
开发者ID:spotify,项目名称:spydra,代码行数:7,代码来源:GcpUtils.java


示例20: listBucket

import com.google.cloud.storage.Bucket; //导入依赖的package包/类
public Page<Blob> listBucket(String bucketName, String directory) {
  Bucket bucket = Objects.requireNonNull(storage.get(bucketName, Storage.BucketGetOption.fields()),
          "Please provide bucket name.");
  Page<Blob> blobs = bucket.list(Storage.BlobListOption.prefix(directory));
  return blobs;
}
 
开发者ID:spotify,项目名称:spydra,代码行数:7,代码来源:GcpUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ProjectPackager类代码示例发布时间:2022-05-22
下一篇:
Java NCSARequestLog类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap