本文整理汇总了Java中com.google.api.client.json.JsonGenerator.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.serialize方法的具体用法?Java JsonGenerator.serialize怎么用?Java JsonGenerator.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.client.json.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.serialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTempJsonKeyFile
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
public static String createTempJsonKeyFile(String clientEmail,
PrivateKey privateKey) throws
IOException {
final File tempJsonKey = File.createTempFile("temp-key", ".json",
getTempFolder());
JsonGenerator jsonGenerator = null;
try {
jsonGenerator = new JacksonFactory()
.createJsonGenerator(new FileOutputStream(tempJsonKey),
Charset.forName("UTF-8"));
jsonGenerator.enablePrettyPrint();
jsonGenerator.serialize(createJsonKey(clientEmail, privateKey));
} finally {
if (jsonGenerator != null) {
jsonGenerator.close();
}
}
return tempJsonKey.getAbsolutePath();
}
示例2: createTempLegacyJsonKeyFileWithMissingClientEmail
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
public static String createTempLegacyJsonKeyFileWithMissingClientEmail()
throws IOException {
final File tempLegacyJsonKey =
File.createTempFile("temp-legacykey", ".json", getTempFolder());
JsonGenerator jsonGenerator = null;
try {
jsonGenerator = new JacksonFactory()
.createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
Charset.forName("UTF-8"));
jsonGenerator.enablePrettyPrint();
jsonGenerator.serialize(createLegacyJsonKeyWithMissingClientEmail());
} finally {
if (jsonGenerator != null) {
jsonGenerator.close();
}
}
return tempLegacyJsonKey.getAbsolutePath();
}
示例3: save
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
private void save() throws IOException {
FileOutputStream fos = new FileOutputStream(file);
try {
JsonGenerator generator = jsonFactory.createJsonGenerator(fos, Charsets.UTF_8);
generator.serialize(credentials);
generator.close();
} finally {
fos.close();
}
}
示例4: save
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
public void save() {
try (FileOutputStream fos = new FileOutputStream(configFile)) {
JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
fos, Charset.forName("UTF-8"));
generator.enablePrettyPrint();
generator.serialize(this);
generator.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
for(ConfigChangeListener listener : this.listeners) {
listener.onConfigChanged();
}
}
示例5: saveEnabledMods
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
private void saveEnabledMods(EnabledMods mods) throws IOException {
try (FileOutputStream fos = new FileOutputStream(
enabledModsFile.toFile())) {
JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
fos, Charset.forName("UTF-8"));
generator.enablePrettyPrint();
generator.serialize(mods);
generator.close();
_enabledMods = mods;
}
}
示例6: createTempLegacyJsonKeyFile
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
public static String createTempLegacyJsonKeyFile(String clientEmail)
throws IOException {
final File tempLegacyJsonKey =
File.createTempFile("temp-legacykey", ".json", getTempFolder());
final JsonGenerator jsonGenerator = new JacksonFactory()
.createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
Charset.forName("UTF-8"));
jsonGenerator.enablePrettyPrint();
jsonGenerator.serialize(createLegacyJsonKey(clientEmail));
jsonGenerator.close();
return tempLegacyJsonKey.getAbsolutePath();
}
示例7: createTempLegacyJsonKeyFileWithMissingWebObject
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
public static String createTempLegacyJsonKeyFileWithMissingWebObject()
throws IOException {
final File tempLegacyJsonKey =
File.createTempFile("temp-legacykey", ".json", getTempFolder());
final JsonGenerator jsonGenerator = new JacksonFactory()
.createJsonGenerator(new FileOutputStream(tempLegacyJsonKey),
Charset.forName("UTF-8"));
jsonGenerator.enablePrettyPrint();
jsonGenerator.serialize(createLegacyJsonKeyWithMissingWebObject());
jsonGenerator.close();
return tempLegacyJsonKey.getAbsolutePath();
}
示例8: storeClientToken
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
private void storeClientToken(final JsonFactory jsonFactory) throws IOException
{
final StringWriter jsonTrWriter = new StringWriter();
final JsonGenerator generator = jsonFactory.createJsonGenerator(jsonTrWriter);
generator.serialize(clientToken);
generator.flush();
generator.close();
FileUtils.writeStringToFile(clientTokenPath.toFile(), jsonTrWriter.toString(), charset);
}
示例9: writeToken
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
private void writeToken() throws IOException {
try (OutputStream outputStream = new FileOutputStream(tokenFile);
OutputStreamWriter outputWriter = new OutputStreamWriter(outputStream)) {
JsonGenerator generator = new JacksonFactory().createJsonGenerator(outputWriter);
generator.enablePrettyPrint();
generator.serialize(token);
generator.flush();
}
}
示例10: downloadMod
import com.google.api.client.json.JsonGenerator; //导入方法依赖的package包/类
private File downloadMod(ApiMod mod) throws IOException {
System.out.println("Starting download for " + mod.getTitle());
String url = mod.getDownloadUrl();
HttpURLConnection connection;
boolean redirect = false;
do {
URL website = new URL(url);
System.out.println("Accessing " + url);
connection = (HttpURLConnection) website.openConnection();
connection.setInstanceFollowRedirects(false);
String location = connection.getHeaderField("Location");
if (location != null) {
connection.disconnect();
url = location.replaceAll("(?i)/(\\d+)\\\\(\\d+)/", "/$1/$2/");
if (!url.startsWith("http"))
url = "http:" + url;
URL u = new URL(url);
String[] parts = u.getPath().split("/");
for (int i = 0; i < parts.length; i++) {
parts[i] = CharEscapers.escapeUriPath(parts[i]);
}
url = u.getProtocol() + "://" + u.getHost() + "/"
+ Joiner.on('/').join(parts)
+ (u.getQuery() != null ? "?" + u.getQuery() : "");
redirect = true;
} else {
redirect = false;
}
} while (redirect);
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
File cacheFile = new File(Config.cachedir, "mod-" + mod.getId()
+ ".zip");
File cacheConfigFile = new File(Config.cachedir, mod.getInfoName());
try (DigestInputStream dis = new DigestInputStream(
connection.getInputStream(), digest);
FileOutputStream fos = new FileOutputStream(cacheFile)) {
IOUtils.copy(dis, fos);
}
try (FileOutputStream fos = new FileOutputStream(cacheConfigFile)) {
JsonGenerator generator = Start.JSON_FACTORY.createJsonGenerator(
fos, Charset.forName("UTF-8"));
generator.enablePrettyPrint();
generator.serialize(mod);
generator.close();
}
System.out.println("Download finished "
+ byteArray2Hex(digest.digest()) + " vs " + mod.getSha1sum());
return cacheFile;
}