本文整理了Java中com.google.api.client.googleapis.util.Utils.getDefaultJsonFactory()
方法的一些代码示例,展示了Utils.getDefaultJsonFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.getDefaultJsonFactory()
方法的具体详情如下:
包路径:com.google.api.client.googleapis.util.Utils
类名称:Utils
方法名:getDefaultJsonFactory
[英]Returns a cached default implementation of the JsonFactory interface.
[中]返回JsonFactory接口的缓存默认实现。
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
/**
* Create a Storage Transfer client using application default credentials and other default
* settings.
*
* @return a Storage Transfer client
* @throws IOException
* there was an error obtaining application default credentials
*/
public static Storagetransfer createStorageTransferClient() throws IOException {
HttpTransport httpTransport = Utils.getDefaultTransport();
JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
GoogleCredential credential =
GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
return createStorageTransferClient(httpTransport, jsonFactory, credential);
}
代码示例来源:origin: com.google.cloud.genomics/google-genomics-dataflow
@Override
public JsonFactory create(PipelineOptions options) {
return Utils.getDefaultJsonFactory();
}
}
代码示例来源:origin: googlegenomics/dataflow-java
@Override
public JsonFactory create(PipelineOptions options) {
return Utils.getDefaultJsonFactory();
}
}
代码示例来源:origin: spotify/async-google-pubsub-client
private static Credential defaultCredential() {
try {
return GoogleCredential.getApplicationDefault(
Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
代码示例来源:origin: googlegenomics/dockerflow
/** Deserialize from json. */
public static <T> T fromJson(String s, Class<T> c) throws IOException {
FileUtils.LOG.debug("Deserializing from json to " + c);
T retval;
// For some reason, this only works for auto-generated Google API
// classes
if (c.toString().startsWith("com.google.api.services.")) {
FileUtils.LOG.debug("Using Google APIs JsonParser");
retval = Utils.getDefaultJsonFactory().createJsonParser(s).parse(c);
} else {
FileUtils.LOG.debug("Using Gson");
retval = new GsonBuilder().setLenient().create().fromJson(s, c);
}
return retval;
}
代码示例来源:origin: GoogleCloudPlatform/cloud-pubsub-samples-java
/**
* Builds a new Pubsub client with default HttpTransport and
* JsonFactory and returns it.
*
* @return Pubsub client.
* @throws IOException when we can not get the default credentials.
*/
public static Pubsub getClient() throws IOException {
return getClient(Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory());
}
代码示例来源:origin: org.apache.beam/beam-examples-java
/** Builds a new Pubsub client with default HttpTransport and JsonFactory and returns it. */
public static Pubsub getClient() throws IOException {
return getClient(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* {@link Beta} <br/>
* Return a credential defined by a Json file.
*
* @param credentialStream the stream with the credential definition.
* @return the credential defined by the credentialStream.
* @throws IOException if the credential cannot be created from the stream.
*/
@Beta
public static GoogleCredential fromStream(InputStream credentialStream) throws IOException {
return fromStream(
credentialStream,
Utils.getDefaultTransport(),
Utils.getDefaultJsonFactory());
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* {@link Beta} <br/>
* Returns the Application Default Credentials.
*
* <p>Returns the Application Default Credentials which are credentials that identify and
* authorize the whole application. This is the built-in service account if running on Google
* Compute Engine or the credentials file from the path in the environment variable
* GOOGLE_APPLICATION_CREDENTIALS.</p>
*
* @return the credential instance.
* @throws IOException if the credential cannot be created in the current environment.
*/
@Beta
public static GoogleCredential getApplicationDefault() throws IOException {
return getApplicationDefault(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory());
}
代码示例来源:origin: com.google.cloud.genomics/google-genomics-utils
private int readTimeout = DEFAULT_READ_TIMEOUT;
private int numRetries = DEFAULT_NUMBER_OF_RETRIES;
private JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
private Optional<String> rootUrl = Optional.absent();
private Optional<String> servicePath = Optional.absent();
代码示例来源:origin: spotify/styx
private static Container createGkeClient() {
try {
final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final GoogleCredential credential =
GoogleCredential.getApplicationDefault(httpTransport, jsonFactory)
.createScoped(ContainerScopes.all());
return new Container.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(SERVICE_NAME)
.build();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: firebase/firebase-admin-java
private static FirebaseOptions getOptionsFromEnvironment() throws IOException {
String defaultConfig = System.getenv(FIREBASE_CONFIG_ENV_VAR);
if (Strings.isNullOrEmpty(defaultConfig)) {
return new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.build();
}
JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
JsonParser parser;
if (defaultConfig.startsWith("{")) {
parser = jsonFactory.createJsonParser(defaultConfig);
} else {
FileReader reader;
reader = new FileReader(defaultConfig);
parser = jsonFactory.createJsonParser(reader);
}
parser.parseAndClose(builder);
builder.setCredentials(GoogleCredentials.getApplicationDefault());
return builder.build();
}
}
代码示例来源:origin: spotify/styx
private static ServiceAccountKeyManager createServiceAccountKeyManager() {
try {
final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final GoogleCredential credential = GoogleCredential
.getApplicationDefault(httpTransport, jsonFactory)
.createScoped(IamScopes.all());
final Iam iam = new Iam.Builder(
httpTransport, jsonFactory, credential)
.setApplicationName(SERVICE_NAME)
.build();
return new ServiceAccountKeyManager(iam);
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: spotify/styx
@Override
public Authenticator apply(AuthenticatorConfiguration configuration) {
final HttpTransport httpTransport;
try {
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
} catch (GeneralSecurityException | IOException e) {
throw new RuntimeException(e);
}
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final GoogleIdTokenVerifier googleIdTokenVerifier =
buildGoogleIdTokenVerifier(httpTransport, jsonFactory);
final GoogleCredential credential = loadCredential();
final CloudResourceManager cloudResourceManager =
buildCloudResourceManager(httpTransport, jsonFactory, credential, configuration.service());
final Iam iam = buildIam(httpTransport, jsonFactory, credential, configuration.service());
final Authenticator validator =
new Authenticator(googleIdTokenVerifier, cloudResourceManager, iam, configuration);
try {
validator.cacheResources();
} catch (IOException e) {
throw new RuntimeException(e);
}
return validator;
}
}
代码示例来源:origin: spotify/zoltar
/**
* Creates a Google Cloud ML Engine backed model.
*
* @param id {@link Model.Id} needs to be created with the following format:
* <pre>"projects/{PROJECT_ID}/models/{MODEL_ID}"</pre>
* or
* <pre>"projects/{PROJECT_ID}/models/{MODEL_ID}/versions/{MODEL_VERSION}"</pre>
*/
public static MlEngineModel create(final Model.Id id)
throws IOException, GeneralSecurityException {
final HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
final GoogleCredential credential =
GoogleCredential.getApplicationDefault()
.createScoped(CloudMachineLearningEngineScopes.all());
final CloudMachineLearningEngine mlEngine =
new CloudMachineLearningEngine.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(APPLICATION_NAME)
.build();
return new AutoValue_MlEngineModel(id, mlEngine, httpTransport);
}
代码示例来源:origin: spotify/styx
final JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
内容来源于网络,如有侵权,请联系作者删除!