Enviar búsqueda
Cargar
GCS - Java to store data in Cloud Storage
•
0 recomendaciones
•
747 vistas
Simon Su
Seguir
Tecnología
Educación
Denunciar
Compartir
Denunciar
Compartir
1 de 5
Descargar ahora
Descargar para leer sin conexión
Recomendados
Microservice Protection With WSO2 Identity Server
Microservice Protection With WSO2 Identity Server
Anupam Gogoi
Kerberos survival guide
Kerberos survival guide
J.D. Wade
MongoDB World 2019: MongoDB Implementation at T-Mobile
MongoDB World 2019: MongoDB Implementation at T-Mobile
MongoDB
Kerberos Survival Guide: SharePoint Saturday Nashville 2015
Kerberos Survival Guide: SharePoint Saturday Nashville 2015
J.D. Wade
SharePoint Saturday Kansas City - Kerberos Survival Guide
SharePoint Saturday Kansas City - Kerberos Survival Guide
J.D. Wade
Kerberos survival guide - SPS Ozarks 2010
Kerberos survival guide - SPS Ozarks 2010
J.D. Wade
Kerberos
Kerberos
Dmytro Andriychenko
Bt0083 server side programing
Bt0083 server side programing
Techglyphs
Recomendados
Microservice Protection With WSO2 Identity Server
Microservice Protection With WSO2 Identity Server
Anupam Gogoi
Kerberos survival guide
Kerberos survival guide
J.D. Wade
MongoDB World 2019: MongoDB Implementation at T-Mobile
MongoDB World 2019: MongoDB Implementation at T-Mobile
MongoDB
Kerberos Survival Guide: SharePoint Saturday Nashville 2015
Kerberos Survival Guide: SharePoint Saturday Nashville 2015
J.D. Wade
SharePoint Saturday Kansas City - Kerberos Survival Guide
SharePoint Saturday Kansas City - Kerberos Survival Guide
J.D. Wade
Kerberos survival guide - SPS Ozarks 2010
Kerberos survival guide - SPS Ozarks 2010
J.D. Wade
Kerberos
Kerberos
Dmytro Andriychenko
Bt0083 server side programing
Bt0083 server side programing
Techglyphs
JCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop Setup
Simon Su
GAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannel
Simon Su
GAE Java IDE installation
GAE Java IDE installation
Simon Su
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
Simon Su
GCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage Guide
Simon Su
EmbulkのGCS/BigQuery周りのプラグインについて
EmbulkのGCS/BigQuery周りのプラグインについて
Satoshi Akama
Google Cloud Monitoring
Google Cloud Monitoring
Simon Su
Google Cloud Platform專案建立說明
Google Cloud Platform專案建立說明
Simon Su
Try Cloud Spanner
Try Cloud Spanner
Simon Su
均一Gae甘苦談
均一Gae甘苦談
蘇 倚恩
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
LiquidHub
Administrators manual
Administrators manual
ScrumDesk
Administrators manual
Administrators manual
ScrumDesk
Data load utility
Data load utility
Laxmi Kanth Kshatriya
ASP.NET Lecture 5
ASP.NET Lecture 5
Julie Iskander
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
Josimar Caitano
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012
Michael Noel
Apache Web Services
Apache Web Services
lkurriger
Open-VPN Server
Open-VPN Server
Manish Kc
User id installation and configuration
User id installation and configuration
Alberto Rivai
MATERIAL.pdf
MATERIAL.pdf
KattaVenkatesh4
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Niels de Bruijn
Más contenido relacionado
Destacado
JCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop Setup
Simon Su
GAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannel
Simon Su
GAE Java IDE installation
GAE Java IDE installation
Simon Su
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
Simon Su
GCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage Guide
Simon Su
EmbulkのGCS/BigQuery周りのプラグインについて
EmbulkのGCS/BigQuery周りのプラグインについて
Satoshi Akama
Google Cloud Monitoring
Google Cloud Monitoring
Simon Su
Google Cloud Platform專案建立說明
Google Cloud Platform專案建立說明
Simon Su
Try Cloud Spanner
Try Cloud Spanner
Simon Su
均一Gae甘苦談
均一Gae甘苦談
蘇 倚恩
Destacado
(10)
JCConf2016 - Dataflow Workshop Setup
JCConf2016 - Dataflow Workshop Setup
GAE - Using CloudStorage through FileReadChannel
GAE - Using CloudStorage through FileReadChannel
GAE Java IDE installation
GAE Java IDE installation
JCConf 2016 - Dataflow Workshop Labs
JCConf 2016 - Dataflow Workshop Labs
GCE Windows Serial Console Usage Guide
GCE Windows Serial Console Usage Guide
EmbulkのGCS/BigQuery周りのプラグインについて
EmbulkのGCS/BigQuery周りのプラグインについて
Google Cloud Monitoring
Google Cloud Monitoring
Google Cloud Platform專案建立說明
Google Cloud Platform專案建立說明
Try Cloud Spanner
Try Cloud Spanner
均一Gae甘苦談
均一Gae甘苦談
Similar a GCS - Java to store data in Cloud Storage
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
LiquidHub
Administrators manual
Administrators manual
ScrumDesk
Administrators manual
Administrators manual
ScrumDesk
Data load utility
Data load utility
Laxmi Kanth Kshatriya
ASP.NET Lecture 5
ASP.NET Lecture 5
Julie Iskander
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
Josimar Caitano
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012
Michael Noel
Apache Web Services
Apache Web Services
lkurriger
Open-VPN Server
Open-VPN Server
Manish Kc
User id installation and configuration
User id installation and configuration
Alberto Rivai
MATERIAL.pdf
MATERIAL.pdf
KattaVenkatesh4
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Niels de Bruijn
Azure AD B2C Webinar Series: Custom Policies Part 2 Policy Walkthrough
Azure AD B2C Webinar Series: Custom Policies Part 2 Policy Walkthrough
Vinu Gunasekaran
Lamdba micro service using Amazon Api Gateway
Lamdba micro service using Amazon Api Gateway
Mike Becker
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Michael Noel
Azure hands on lab
Azure hands on lab
Atanas Gergiminov
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
Michael Noel
MS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applications
Spiffy
DCHQ Cloud Application Platform | Linux Containers | Docker PaaS
DCHQ Cloud Application Platform | Linux Containers | Docker PaaS
dchq
Pre Install Databases
Pre Install Databases
LiquidHub
Similar a GCS - Java to store data in Cloud Storage
(20)
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
Administrators manual
Administrators manual
Administrators manual
Administrators manual
Data load utility
Data load utility
ASP.NET Lecture 5
ASP.NET Lecture 5
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
[AD/CS] Windows Server 2016 - CA Enterprise - Parte02
SharePoint Security in an Insecure World - AUSPC 2012
SharePoint Security in an Insecure World - AUSPC 2012
Apache Web Services
Apache Web Services
Open-VPN Server
Open-VPN Server
User id installation and configuration
User id installation and configuration
MATERIAL.pdf
MATERIAL.pdf
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Single Sign-On for APEX applications based on Kerberos (Important: latest ver...
Azure AD B2C Webinar Series: Custom Policies Part 2 Policy Walkthrough
Azure AD B2C Webinar Series: Custom Policies Part 2 Policy Walkthrough
Lamdba micro service using Amazon Api Gateway
Lamdba micro service using Amazon Api Gateway
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Security for SharePoint in an Insecure World - SharePoint Connections Amsterd...
Azure hands on lab
Azure hands on lab
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
SPTechCon SFO 2012 - Understanding the Five Layers of SharePoint Security
MS Cloud Day - Deploying and monitoring windows azure applications
MS Cloud Day - Deploying and monitoring windows azure applications
DCHQ Cloud Application Platform | Linux Containers | Docker PaaS
DCHQ Cloud Application Platform | Linux Containers | Docker PaaS
Pre Install Databases
Pre Install Databases
Más de Simon Su
Kubernetes Basic Operation
Kubernetes Basic Operation
Simon Su
Google IoT Core 初體驗
Google IoT Core 初體驗
Simon Su
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
Simon Su
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
Simon Su
Google Cloud Platform Special Training
Google Cloud Platform Special Training
Simon Su
GCPNext17' Extend 開始GCP了嗎?
GCPNext17' Extend 開始GCP了嗎?
Simon Su
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKE
Simon Su
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
Simon Su
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow Introduction
Simon Su
Brocade - Stingray Application Firewall
Brocade - Stingray Application Firewall
Simon Su
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
Simon Su
Docker in Action
Docker in Action
Simon Su
Google I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News Update
Simon Su
IThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOps
Simon Su
Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3
Simon Su
Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧
Simon Su
GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)
Simon Su
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
Simon Su
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
Simon Su
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
Simon Su
Más de Simon Su
(20)
Kubernetes Basic Operation
Kubernetes Basic Operation
Google IoT Core 初體驗
Google IoT Core 初體驗
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
JSDC 2017 - 使用google cloud 從雲到端,動手刻個IoT
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
GCPUG.TW meetup #28 - GKE上運作您的k8s服務
Google Cloud Platform Special Training
Google Cloud Platform Special Training
GCPNext17' Extend 開始GCP了嗎?
GCPNext17' Extend 開始GCP了嗎?
Google Cloud Computing compares GCE, GAE and GKE
Google Cloud Computing compares GCE, GAE and GKE
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
GCPUG meetup 201610 - Dataflow Introduction
GCPUG meetup 201610 - Dataflow Introduction
Brocade - Stingray Application Firewall
Brocade - Stingray Application Firewall
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
使用 Raspberry pi + fluentd + gcp cloud logging, big query 做iot 資料搜集與分析
Docker in Action
Docker in Action
Google I/O 2016 Recap - Google Cloud Platform News Update
Google I/O 2016 Recap - Google Cloud Platform News Update
IThome DevOps Summit - IoT、docker與DevOps
IThome DevOps Summit - IoT、docker與DevOps
Google Cloud Platform Introduction - 2016Q3
Google Cloud Platform Introduction - 2016Q3
Google I/O Extended 2016 - 台北場活動回顧
Google I/O Extended 2016 - 台北場活動回顧
GCS - Access Control Lists (中文)
GCS - Access Control Lists (中文)
Google Cloud Platform - for Mobile Solutions
Google Cloud Platform - for Mobile Solutions
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(下)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
JCConf 2015 - 輕鬆學google的雲端開發 - Google App Engine入門(上)
Último
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
Stephanie Beckett
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
Raghuram Pandurangan
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
MounikaPolabathina
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
LoriGlavin3
How to write a Business Continuity Plan
How to write a Business Continuity Plan
Databarracks
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
2toLead Limited
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
DianaGray10
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
Lars Bell
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
Pixlogix Infotech
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Hervé Boutemy
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
LoriGlavin3
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Dilum Bandara
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
BookNet Canada
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
mohitsingh558521
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
Nicole Novielli
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Fwdays
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
Manik S Magar
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Sergiu Bodiu
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Mark Simos
Último
(20)
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
How to write a Business Continuity Plan
How to write a Business Continuity Plan
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
GCS - Java to store data in Cloud Storage
1.
GCS - Java
to store data in Cloud Storage 目錄 目錄 Step1: 申請Service Account,並將相關資訊儲存起來 Step2: Java程式開發 Step1: 申請Service Account,並將相關資訊儲存起來 選擇Service Account,點選Create Client ID之後,系統會直接下載一個xxxprivate.p12的檔案,該 檔案的密碼為”notasecret”,該密碼在需要做轉換pem檔案時候可以用到。
2.
建立好的Service Account大致如下: 其中Email address跟剛剛下載的*.p12檔案會在Java程式中用到 Step2: Java程式開發 Java程式說明如下: 前置參數設定: /** Service Account 的 Email */ private static final String SERVICE_ACCOUNT_EMAIL = "86083545333...tkhf@developer.gserviceaccount.com"; /** 欲列表的Bucket名稱,名稱即可,不用gs:// */ private static final String BUCKET_NAME = "youtbucketname"; /** p12檔案的位置,最好給訂絕對路徑 */ private static final String keypath = "pathtoyourprivatekey2.p12"; 設定credential相關參數 // 建制service account credential. GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(SERVICE_ACCOUNT_EMAIL) .setServiceAccountScopes(Collections.singleton(STORAGE_SCOPE))
3.
.setServiceAccountPrivateKeyFromP12File(new File(keypath)) .build(); 透過HTTP Request來操作Cloud Storage // 設定Request相關參數 String URI = "https://storage.googleapis.com/" + BUCKET_NAME; HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential); GenericUrl url = new GenericUrl(URI); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); // 設定要傳輸的參數 Source xmlInput = new StreamSource(new StringReader(content)); StreamResult xmlOutput = new StreamResult(new StringWriter()); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indentamount", "2"); transformer.transform(xmlInput, xmlOutput); // 列印XML結果 System.out.println("nBucket listing for " + BUCKET_NAME + ":n"); System.out.println(xmlOutput.getWriter().toString()); 完整程式記錄如下: import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.nio.charset.Charset; import java.util.Collections; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpRequest; import com.google.api.client.http.HttpRequestFactory; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory;
4.
import com.google.api.client.json.jackson2.JacksonFactory; import com.google.api.client.util.Preconditions; import com.google.common.io.Files; public class StorageServiceAccountSample { /** Service Account 的 Email */ private static final String SERVICE_ACCOUNT_EMAIL = "86083545333...tkhf@developer.gserviceaccount.com"; /** 欲列表的Bucket名稱,名稱即可,不用gs:// */ private static final String BUCKET_NAME = "youtbucketname"; private static final String keypath = "pathtoyourprivatekey2.p12"; /** Google Cloud Storage OAuth 2.0 scope,這邊給予Read+Write權限 */ private static final String STORAGE_SCOPE = "https://www.googleapis.com/auth/devstorage.read_write"; /** Global instance of the HTTP transport. */ private static HttpTransport httpTransport; /** Global instance of the JSON factory. */ private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); public static void main(String[] args) { try { try { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); // 建制service account credential. GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(SERVICE_ACCOUNT_EMAIL) .setServiceAccountScopes(Collections.singleton(STORAGE_SCOPE)) .setServiceAccountPrivateKeyFromP12File(new File(keypath)) .build(); // Set up and execute Google Cloud Storage request. String URI = "https://storage.googleapis.com/" + BUCKET_NAME; HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential); GenericUrl url = new GenericUrl(URI); HttpRequest request = requestFactory.buildGetRequest(url); HttpResponse response = request.execute(); String content = response.parseAsString(); // Instantiate transformer input Source xmlInput = new StreamSource(new StringReader(content)); StreamResult xmlOutput = new StreamResult(new StringWriter()); // Configure transformer Transformer transformer = TransformerFactory.newInstance().newTransformer(); // An identity transformer transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd");
5.
transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indentamount", "2"); transformer.transform(xmlInput, xmlOutput); // Pretty print the output XML. System.out.println("nBucket listing for " + BUCKET_NAME + ":n"); System.out.println(xmlOutput.getWriter().toString()); System.exit(0); } catch (IOException e) { System.err.println(e.getMessage()); } } catch (Throwable t) { t.printStackTrace(); } System.exit(1); } }
Descargar ahora